Customize UIView &UITextField

使用自定义的UIView时,override awakeFromNib() 命令,为UIView设置倒角,添加阴影:

    override func awakeFromNib() {
        super.awakeFromNib()

        //设置倒角
        layer.cornerRadius = 4.0

        //添加阴影
        layer.shadowColor = UIColor(red: COLOR_SHADOW, green: COLOR_SHADOW, blue: COLOR_SHADOW, alpha: 8.0).CGColor
        layer.shadowOffset = CGSizeMake(0.0, 1.0)
        layer.shadowOpacity = 0.8
        layer.shadowRadius = 2.0
    }

使用自定义的UITextField时,override textRectForBounds(bounds: CGRect) -> CGRect & editingRectForBounds(bounds: CGRect) -> CGRect 命令,设置自定义UITextField的缩进量(placeholder & text):

    override func textRectForBounds(bounds: CGRect) ->CGRect {
    return CGRectInset(bounds, 10.0, 0.0)
    }

    override func editingRectForBounds(bounds: CGRect) -> CGRect {
    return CGRectInset(bounds, 10.0, 0.0)
    }

你可能感兴趣的:(uiview,uiTextFiel,阴影,缩进,iOS自学,Swift)