[英]ios swift 3 xcode8 beta rounded imageView
在我的項目中,我使用以下代碼使我的圖像呈圓形:
profileImage.layer.cornerRadius = profileImage.frame.size.width / 2
profileImage.clipsToBounds = true
我還對我的圖像使用了限制,使其width = hight
和其他限制。
在將我的項目升級到xcode 8 beta和 swift 3 之后,我設置為四舍五入的所有圖像視圖都消失了,當我刪除使其四舍五入的代碼或刪除所有約束時,它們再次出現。
但我仍然需要將它們四舍五入。 任何人都可以幫助我解決問題。 謝謝
我遇到了同樣的問題,解決方案只是在修改圖層之前移動一行代碼。 嘗試應用布局更改:
self.view.layoutIfNeeded()
在您的代碼之前:
profileImage.layer.cornerRadius = profileImage.frame.size.width/2
profileImage.clipsToBounds = true
或者
將與框架/層相關的代碼放入viewDidLayoutSubviews()
方法中:
override func viewDidLayoutSubviews() {
profileImage.layer.cornerRadius = profileImage.frame.size.width/2
profileImage.clipsToBounds = true
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.