2016-01-22 17 views
4

這是我的問題:我試圖繞UIImageView的頂角看起來像一個圓角的UIButton。我使用的口罩要做到這一點,但結果我是不是我真的很期待......像UIButton一樣的UIImageView的圓角頂部

我使用以下擴展名:

extension UIView 
{ 
    func roundCorners(corners:UIRectCorner, radius: CGFloat) 
    { 
    let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) 
    let mask = CAShapeLayer() 
    mask.path = path.CGPath 
    self.layer.mask = mask 
    } 
} 

調用它像這樣在我的代碼:

imageView.roundCorners([.TopLeft, .TopRight], radius: 80) 

這裏是結果: Rounded corners error

我想有上角看起來像底角(底角s是半徑爲10的UIButton邊角)但我看不到錯誤在哪裏...

謝謝大家的幫助!

編輯:我用的是正確的代碼,我只是沒有注意到我的UIImageView比的UIImage較大,因此怪異的角落......我創建的UIImageView編程,因此沒注意到大小不同...新手的錯誤...

謝謝大家的幫助!

+0

我不知道爲什麼,但後期將不會顯示我的第一線,他說「大家好」 ......不要怪我不說你好! :( – Dliix

+0

爲什麼你用半徑= 80調用它?用10調用,看看是否有效 – Gandalf

+0

你可以通過cocoapods使用WHRoundedImageView:請參閱下面的鏈接:https://cocoapods.org/pods/WHRoundedImageView – AlexWoe89

回答

1

使用此值:

imageView([.TopLeft, .TopRight], radius: 20) 

Result is