iOS:向下移动 UITextField 的底部边框

Posted

技术标签:

【中文标题】iOS:向下移动 UITextField 的底部边框【英文标题】:iOS: Moving bottom border of UITextField down 【发布时间】:2016-08-02 06:26:40 【问题描述】:

我通过这种方式为 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 的高度:

如果我以编程方式设置它,应用程序会在刷新可设计对象时挂起(我使用的是UITextFieldIBDesignable 子类)。

【问题讨论】:

看到这个对你有帮助的时候***.com/questions/38303520/… 【参考方案1】:

选择显示属性检查器然后更改边框样式

见下图

【讨论】:

以上是关于iOS:向下移动 UITextField 的底部边框的主要内容,如果未能解决你的问题,请参考以下文章