TextView边框颜色和边框半径未设置

时间:2016-10-24 07:22:52

标签: ios swift uitextview ibdesignable ibinspectable

我想通过界面设置UITextView的角半径。但我无法做到这一点。此代码适用于UILabelUIButton,但在UITextView中出错 Intializer不会覆盖超类中指定的初始化程序。

class MyText: UITextView {
        @IBInspectable var borderColor: UIColor = UIColor.whiteColor() {
            didSet {
                layer.borderColor = borderColor.CGColor
            }
        }


        @IBInspectable var borderWidth: CGFloat = 1.0 {
            didSet {
                layer.borderWidth = borderWidth
            }
        }

        @IBInspectable var cornurRadius: CGFloat = 1.0 {
            didSet {
                layer.cornerRadius = cornurRadius
                clipsToBounds = true
            }
        }

        //MARK: Initializers
        override init(frame : CGRect) {
            super.init(frame : frame)
            setup()
            configure()
        }

        convenience init() {
            self.init(frame:CGRectZero)
            setup()
            configure()
        }

        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            setup()
            configure()
        }


        override func awakeFromNib() {
            super.awakeFromNib()
            setup()
            configure()
        }

        override func prepareForInterfaceBuilder() {
            super.prepareForInterfaceBuilder()
            setup()
            configure()
        }

        func setup() {
            layer.borderColor = UIColor.whiteColor().CGColor
            layer.borderWidth = 1.0
            layer.cornerRadius = 1.0
        }

        func configure() {
            layer.borderColor = borderColor.CGColor
            layer.borderWidth = borderWidth
            layer.cornerRadius = cornurRadius
        }

        override func layoutSubviews() {
            super.layoutSubviews()
        }

    }

0 个答案:

没有答案