UIlabel layer.cornerRadius not working in iOS 7.1

后端 未结 8 1904
时光说笑
时光说笑 2021-01-30 04:40

I\'m currently looking at a UILabel with the property addMessageLabel.layer.cornerRadius = 5.0f; On a device with iOS 7.0 installed, it has rounded corners. On a de

8条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 05:11

    Add the Following Code as extension for UIView

    //// Story board Extra Feature for create border radius, border width and border Color
    extension UIView {
        /// corner radius
        @IBInspectable var borderColor: UIColor? {
            set {
                layer.borderColor = newValue!.cgColor
            }
            get {
                if let color = layer.borderColor {
                    return UIColor(cgColor: color)
                } else {
                    return nil
                }
            }
        }
        @IBInspectable var borderWidth: CGFloat {
            set {
                layer.borderWidth = newValue
            }
            get {
                return layer.borderWidth
            }
        }
        @IBInspectable var cornerRadius: CGFloat {
            set {
                layer.cornerRadius = newValue
                clipsToBounds = newValue > 0
            }
            get {
                return layer.cornerRadius
            }
        }
    }
    

    After that you will get the following attributes in interface builder itself.!

提交回复
热议问题