我試圖在Swift中的iOS 9.3中實現一個UIAlertController內的文本字段,不知何故,我得到了填充和文本框周圍的頂部邊框。在UIAlertController中刪除填充和textField周圍的邊框
請參閱下面的屏幕截圖,我在文本框周圍添加了一個厚邊框,以突出顯示填充和頂部邊框/線條。
我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](http://i.imgur.com/5gckZVu.png) – iamlolz
你想刪除哪個填充?左上方? –