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

标签 ios swift uiview uitextfield

我用这种方式为 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)

我得到这个:

enter image description here

我想将边框向下移动。为此,我以这种方式设置边框:

bottomLine.frame = CGRectMake(0.0, self.frame.height + 5, self.frame.width, CGFloat(borderWidth))

这里我将它增加了 5px。但它超出了文本字段的框架。但是我无法调整 UITextField 的高度:

enter image description here

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

最佳答案

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

见下图enter image description here

关于iOS:向下移动 UITextField 的底部边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38713153/

相关文章:

swift - 平滑色度键的边缘 -CoreImage

ios - 当我向 navigationItem 添加更多按钮时,如何使 navigationItem.titleView 居中?

ios - 想要将 API 数据显示到标签(Swift、Alamofire)

ios - [self.window makeKeyAndVisible]处的异常breakPoint

php - Stripe - 通过 PHP、iOS 和 Alamofire 进行部分退款

ios - 格式指定类型 'int' 但参数的类型为 'UIViewContentMode'

ios - 过渡动画中的闪烁(模拟器?)

swift - 在 Swift 中显示来自解析的图像

objective-c - 像 Objective C 一样隐藏的 Swift 覆盖属性集

iphone - UIView drawRect 绘图线宽度错误