标签:
//
// RBCustomTextField.swift
//
// Created by Touch on 16/4/27.
// Copyright © 2016年 renrenbx. All rights reserved.
//
import Foundation
class RBCustomTextField: UITextField {
override init(frame: CGRect) {
super.init(frame: frame)
}
// 编辑状态内容显示位置
override func editingRectForBounds(bounds: CGRect) -> CGRect {
super.editingRectForBounds(bounds)
var newBounds = bounds
if self.leftView?.frame.size.width > 0{
newBounds.origin.x = bounds.origin.x + (self.leftView?.frame.size.width)!
}else{
newBounds.origin.x = bounds.origin.x + 8
}
newBounds.origin.y = bounds.origin.y + 1
return newBounds
}
// 解决输入问题位置偏移问题
override func drawTextInRect(rect: CGRect) {
super.drawTextInRect(CGRect(x: 8, y: self.frame.origin.y + 5.5, width: 0, height: 0))
}
// 占位符偏移
override func placeholderRectForBounds(bounds: CGRect) -> CGRect {
super.placeholderRectForBounds(bounds)
echo("self.frame",self.frame)
echo("bounds",bounds)
var newBounds = bounds
newBounds.origin.x = bounds.origin.x + 8
// newBounds.origin.y = 3
echo("newBounds",newBounds)
return newBounds
}
// 解决占位符位置靠上问题
override func drawPlaceholderInRect(rect: CGRect) {
super.drawPlaceholderInRect(CGRect(x: 0, y: self.frame.size.height * 0.5 - 1, width: 0, height: 0))
}
// 左视图 位置
override func leftViewRectForBounds(bounds: CGRect) -> CGRect {
super.leftViewRectForBounds(bounds)
let newBounds = CGRect(x: 0, y: 0, width: self.frame.size.height, height: self.frame.size.height)
return newBounds
}
// 右视图 位置
override func rightViewRectForBounds(bounds: CGRect) -> CGRect {
super.rightViewRectForBounds(bounds)
let newBounds = CGRect(x: self.frame.size.width - self.frame.size.height, y: 0, width: self.frame.size.height, height: self.frame.size.height)
return newBounds
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
标签:
原文地址:http://www.cnblogs.com/madarax/p/5474565.html