如何移除 UIAlertActionController 中呈现的 UITextField 的外边框 [英] How to remove the outer border of UITextField presented in UIAlertActionController

查看:29
本文介绍了如何移除 UIAlertActionController 中呈现的 UITextField 的外边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向我的警报控制器添加多个 UITextField,我不希望它们周围出现丑陋的黑框.我知道这不是 textField 的边框属性,因为我已经尝试设置它并影响实际的 textField,而不是框.

I am adding multiple UITextFields to my alert controller, and I don't want that ugly black box around them. I know it's not the border property of the textField, because I have tried setting that and that influences the actual textField, not the box.

我试过了

textField.superview?.backgroundColor = UIColor.redColor()textField.superview?.layer.borderColor = UIColor.redColor().CGColor

设置背景颜色按预期工作,填充文本字段和黑色边框"之间的空间,但在 superview.layer 上设置 borderColor 或 borderWidth 什么也不做.有什么想法吗?

Setting the background Color works as expected, filling in the space between the textfield and the "black border" but setting the borderColor or borderWidth on superview.layer do nothing. Any ideas?

推荐答案

我最终继承了 UIAlertController.

I ended up subclassing UIAlertController.

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    for field in textFields! as [UITextField] {
        field.superview?.superview?.layer.borderWidth = 2
        field.superview?.superview?.layer.borderColor = UIColor.whiteColor().CGColor
    }
}

这篇关于如何移除 UIAlertActionController 中呈现的 UITextField 的外边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆