我用这种方式为 UITextField 添加了底部边框:
let bottomLine = CALayer()
bottomLine.frame = CGRectMake(0.0, self.frame.height, self.frame.width, CGFloat(borderWidth))
bottomLine.backgroundColor = borderColor.CGColor
self.borderStyle = UITextBorderStyle.None
self.layer.addSublayer(bottomLine)
我得到这个:
我想将边框向下移动。为此,我以这种方式设置边框:
bottomLine.frame = CGRectMake(0.0, self.frame.height + 5, self.frame.width, CGFloat(borderWidth))
这里我将它增加了 5px。但它超出了文本字段的框架。但是我无法调整 UITextField
的高度:
如果我以编程方式设置它,应用程序会在刷新可设计项时挂起(我正在使用 UITextField
的 IBDesignable
子类)。
最佳答案
关于iOS:向下移动 UITextField 的底部边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38713153/