2015-11-06 74 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