swift 自定义输入框frame、placeholder frame的textfield

/// 自定义UITextField
class JKTextField: UITextField{
    
    /// 传入frame
    var placeholderFrame:CGRect?

    /// 设置placeholderframe
    override func placeholderRectForBounds(bounds: CGRect) -> CGRect {
        return placeholderFrame!
    }
    
    /// 设置编辑框frame
    override func editingRectForBounds(bounds: CGRect) -> CGRect {
        return placeholderFrame!
    }
    
    /// 文本显示的frame
    override func drawTextInRect(rect: CGRect) {
        super.drawTextInRect(placeholderFrame!)
    }
    
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    /// 自定义初始化方法,传入frame
    init (frame:CGRect ,placeholderFrame:CGRect){
        self.placeholderFrame = placeholderFrame
        super.init(frame: frame)
        self.returnKeyType = .Done
    }
}

你可能感兴趣的:(iOS)