我希望我的图像显示为完整的360度圆。当我构建并运行时,我的图像显示为椭圆形。
ios - 使UIImageView舍入-LMLPHP

@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/

10-10 20:49