在 Objective-C 中,这条代码
self.mainImageView.layer.cornerRadius = CGRectGetWidth(self.mainImageView.frame)/4.0f;
它很有效,我用类比法在Swift中尝试过
self.mainImageView.layer.cornerRadius = CGRectGetWidth(self.mainImageView.frame)/4.0
并且它不会改变任何东西,四个角还是和以前一样。此外,Xcode没有显示任何语法错误。Swift是否支持其他方法来实现这个目标?我在这里检查了一些其他线程,通常都是用上面展示的方式在Swift中完成。