【发布时间】:2016-08-11 11:45:47
【问题描述】:
我实现了一个解决方案,将底部边框放置到一个效果很好的文本字段,但我有以下问题。如果我在更大尺寸(iPad mini、iPad Pro)或横向(iPhone6、6s)上启动应用程序,则文本字段下的行不正确拉伸。
我已经为文本字段创建了一个扩展:
extension UITextField {
/**
Customize the UITextField for App
- parameter isPasswordField: Boolean to check if this field is a password field
- author: Simon Zwicker <simon.zwicker@gmail.com>
*/
func customize(isPasswordField: Bool) {
let bottomLine = UIView()
bottomLine.frame = CGRect(x: 0.0, y: self.frame.size.height - 1, width: self.frame.size.width, height: 1.0)
bottomLine.backgroundColor = UIColor.grayColor()
self.addSubview(bottomLine)
self.tintColor = UIColor.grayColor()
if isPasswordField {
self.textColor = UIColor.blueColor()
}
}
我在viewWillLayoutSubviews() 中的文本字段上调用customize() 函数
我是不是在某个地方弄错了?在我将设备置于纵向并返回横向后,它就可以工作了。
文本域的初始大小是正确的,但自定义函数中的 self.frame.size.width 初始值太小。你知道可能发生了什么吗?
【问题讨论】:
标签: ios swift uiview uitextfield border