当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - How can customize boders for a UIButton using UIBuilder and Swift

问题描述:

So I have these buttons, and because both buttons have rounded corners you can see a small gap between them at their aligned corners. I want the top button to have rounded corners on the top and the bottom button to have rounded corners at the bottom, giving the illusion of one big button divided in half.

Is it possible to have a UIButton that has round corners on the top and normal corners on the bottom? I am using XCode 7.

Thanks!

网友答案:

Use this extension:

your_class {
    ...
}

extension UIButton {
    override 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
    }
}

Usage:

your_button.roundCorners([.TopLeft, .TopRight], radius: 10)
分享给朋友:
您可能感兴趣的文章:
随机阅读: