我希望我的图像显示为完整的360度圆。当我构建并运行时,我的图像显示为椭圆形。
@IBOutlet var profileImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
profileImageView.layer.cornerRadius = profileImageView.frame.size.width / 2
profileImageView.clipsToBounds = true
profileImageView.layer.borderColor = UIColor.whiteColor() .CGColor
profileImageView.layer.borderWidth = 3
picker.delegate = self
picker.dataSource = self
milesTextField.inputView = picker
}
最佳答案
似乎您使用了自动布局。而且,当您尝试设置cornerRadius
时,框架的width
尚未完全准备好。在viewDidLoad
方法中,布局尚未准备就绪。您应该将代码放入viewDidLayoutSubviews
方法。
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
profileImageView.layer.cornerRadius = profileImageView.frame.size.width / 2
profileImageView.clipsToBounds = true
profileImageView.layer.borderColor = UIColor.whiteColor() .CGColor
profileImageView.layer.borderWidth = 3
}
关于ios - 使UIImageView舍入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34750902/