在我的快速项目中,我想为我的文本字段添加右侧边框,因为,我在单个tableviewcell中有两个文本字段,所以,我想将它们显示为右侧边框与第一个文本字段分开。
任何建议,谢谢!!
答案 0 :(得分:4)
答案 1 :(得分:0)
试试这个。
CGFloat width = 5;
UIView *bottomBorder = [[UIView alloc] initWithFrame:CGRectMake(self.textField1.frame.size.width - width,0,width,_textField1.frame.size.height)];
[bottomBorder setBackgroundColor:[UIColor redColor]];
[_textField1 addSubview:bottomBorder];
答案 2 :(得分:0)
选择是你的,
方式1:创建IBDesignable&将它分配给class属性中的textfield,
import UIKit
@IBDesignable
class IBDesignableTextField: UITextField {
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
let border = CALayer()
let height = CGFloat(2.0)
border.borderColor = UIColor.darkGray.cgColor
border.frame = CGRect(x: self.frame.size.width - height, y: 0, width: self.frame.size.width, height: self.frame.size.height)
border.borderWidth = height
self.layer.addSublayer(border)
self.layer.masksToBounds = true
}
}
方式2: @Dixit Akabari解释
方式3 :您只需将正确的视图添加到文本字段作为边框图像