UIAertField中的UITextField(border,backgroundColor) [英] UITextField in UIAlertController (border, backgroundColor)

查看:143
本文介绍了UIAertField中的UITextField(border,backgroundColor)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是 UIAlertController 的屏幕截图。我只是玩自定义字体和 textfield 属性,但我无法完成以下任务:

Here is a screenshot of a UIAlertController. I was just playing around custom fonts and textfield properties but I was unable to accomplish the following:


  • 明确背景 UITextField

  • 没有丑陋的边框(黑框),如下所示

当我更多地研究代码和iOS运行时标题时,我能够修改边框和背景颜色,但上述问题仍然存在,因为这些属性属于容器的UITextView 。将背景更改为 clearColor 无效。

As I dived more into the code and iOS runtime headers, I was able to modify border and background color but the above issue still remains as those properties belong to a container UITextView. Changing background to clearColor doesn't help.

有没有人玩过这个?不确定我是否会将我的应用程序投入到生产中,并带有如此难看的文本字段。

Has anybody ever played around with this? Not sure if I would ever take my app into production with such ugly text fields.

编辑(5月13日,15日)以下答案Rory McKinnel已经过iOS 8 - 8.3测试,效果很好。结果如下:

EDIT (May 13, 15) The answer below by Rory McKinnel is tested for iOS 8 - 8.3 and works just fine. The result is below:

推荐答案

对此有一些乐趣。以下似乎有效。很明显,根据需要进行判断,它没有未来的证明,并且是一个远离不工作的补丁。

Had some fun with this. The following seems to work. Obviously judging by what was required, it has no future proofing and is a patch away from not working.

我通过在调试器中遍历视图层次结构来解决这个问题,我注意到了一个UIVisualEffectView。删除它似乎可以为您提供所需的设置,并将包含视图设置为清晰的背景。在不删除视觉效果的情况下,清晰的背景会出于某种原因显示警报视图背后的内容。

I figured this out by walking the view hierarchy in the debugger, from which I noticed a UIVisualEffectView. Removing that seems to give you what you want along with setting the containing view to a clear background. Without removing the visual effect, a clear background shows what is behind the alert view itself for some reason.

UIAlertController *alertController = 
 [UIAlertController alertControllerWithTitle:@"Its Not Pretty!" 
                                     message:@"Some times things get ugly!"                          
                              preferredStyle:UIAlertControllerStyleAlert];

[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){
    textField.text = @"Text: No border and clear 8^)";

 }];
[self presentViewController:alertController animated:TRUE completion:^{
}];

for (UIView* textfield in alertController.textfields) {
    UIView *container = textField.superview;
    UIView *effectView = container.superview.subviews[0];

    if (effectView && [effectView class] == [UIVisualEffectView class]){
        container.backgroundColor = [UIColor clearColor];
        [effectView removeFromSuperview];
    }
}

这篇关于UIAertField中的UITextField(border,backgroundColor)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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