【发布时间】:2016-07-28 23:26:56
【问题描述】:
我正在尝试在 iOS 9.3 的 Swift 中的 UIAlertController 中实现一个文本字段,但不知何故,我在文本字段周围获得了填充和顶部边框。
请看下面的截图,我在文本字段周围添加了一个粗边框以突出显示填充和顶部边框/线条。
我的 UIAlertController 的代码:
func handleLoginForgotPassword() {
// create alert controller
let alertController = UIAlertController(title: "Password Reset", message: "\nEnter your email below and press Reset to reset your password.\n", preferredStyle: .Alert)
// create text field for email
alertController.addTextFieldWithConfigurationHandler { textField -> Void in
let tf = textField
tf.placeholder = "Email Address"
tf.autocorrectionType = .No
tf.autocapitalizationType = .None
tf.backgroundColor = UIColor.whiteColor()
tf.layer.borderWidth = 4.0
tf.heightAnchor.constraintEqualToConstant(50).active = true
// pull email from emailTextField if it exists
tf.text = self.emailTextField.text
}
// create "OK" alert action
let actionReset = UIAlertAction(title: "Reset", style: UIAlertActionStyle.Default) {
UIAlertAction in
NSLog("YES Pressed")
// do something
return
}
// create "Cancel" alert action
let actionCancel = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) {
UIAlertAction in
NSLog("NO Pressed")
// do something
return
}
// add the actions
alertController.addAction(actionReset)
alertController.addAction(actionCancel)
// present the controller
self.presentViewController(alertController, animated: true, completion: nil)
}
这种行为看起来很奇怪,我在搜索类似问题时找不到它的引用。
【问题讨论】:
-
您已将borderWith 设置为4.0,这就是您看到边框的原因。删除那条线,边框就会消失。
-
@ChristianAbella 该边框仅用于说明它周围的填充/边框问题。这里没有边界:http://i.imgur.com/5gckZVu.png
-
您要删除哪个填充?上,左?
-
@ChristianAbella 文本字段周围的填充。我只是希望它本质上看起来像一个普通的文本字段。为什么这个文本字段的边缘有这个空白?以及该区域顶部的线条/边框?
-
我尝试了您的代码,但删除了这两行并且填充消失了:tf.layer.borderWidth = 4.0 tf.heightAnchor.constraintEqualToConstant(50).active = true
标签: ios swift swift2 uitextfield ios9