0

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

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

    }
4

0 回答 0