2015-11-06 70 views
0

我正在用一排按鈕創建一個應用程序。我想設置第一個按鈕和最後一個按鈕的圓角。第一個按鈕與左角和右角的最後一個按鈕。我正在使用下面的代碼。UIbutton iOS的圓角 - Swift

//Following code from viewDidLoad function 
    test_1.roundCorners([.TopLeft, .BottomLeft], radius: 20); 
      test_10.roundCorners([.TopRight, .BottomRight], radius: 20); 

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 
    } 
} 

我的輸出類似下面的截圖來自iphone6 plus

我的ipad2屏幕截圖

enter image description here

Note:的Abobe截圖這樣

enter image description here

請有人幫我找到問題。

編輯:

我需要的輸出需要是這樣

enter image description here

請留下顏色和交叉符號。

+0

檢查我的編輯。這是所需的輸出。 – Amsheer

回答

0

我找到了解決方案。其實解決方案非常簡單。我只是移動viewDidAppear()裏的代碼現在一切正常。

override func viewDidAppear(animated: Bool) { 
     super.viewDidAppear(animated); 
     test_1.roundCorners([.TopLeft, .BottomLeft], radius: 20); 
     test_10.roundCorners([.TopRight, .BottomRight], radius: 20); 
    } 
0

你不應該使用絕對值 - 使用親屬四捨五入角落或進行相應的更改半徑

UIScreen.mainScreen().scale 
UIScreen.mainScreen().nativeScale 

希望,你明白的方向。在iphone6plus上,Retina 3x和iPad 2 2x的20px不一樣。

+0

我該如何修改我的代碼? – Amsheer