【问题标题】:UITextField setting backgroundcolor hides shadowUITextField 设置 backgroundcolor 隐藏阴影
【发布时间】:2011-10-26 08:38:42
【问题描述】:

所以我正在用阴影自定义我的 UITextField.layer:

[userNameField.layer setBorderColor: [[UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1.0] CGColor]];
[userNameField.layer setBorderWidth: 1.0];
[userNameField.layer setCornerRadius:6.0];
[userNameField.layer setShadowOpacity:0.7];
[userNameField.layer setShadowColor:[[UIColor colorWithRed:180/255.0 green:180/255.0 blue:180/255.0 alpha:1.0] CGColor]];
[userNameField.layer setShadowOffset:CGSizeMake(0.5, 0.5)];

这就像一个魅力,但背景是透明的。 现在当我设置背景颜色时:

[userNameField.layer setBackgroundColor:[[UIColor whiteColor] CGColor]];

阴影被覆盖(被背景颜色隐藏)。

有谁知道如何在文本字段上同时设置背景颜色和阴影?

【问题讨论】:

  • 我遇到了同样的问题,当我尝试在文本字段上设置阴影时它不起作用/出现,我没有意识到这是因为我设置了 backgroundColor,所以 +1为那个给 OP!

标签: iphone background uitextfield shadow


【解决方案1】:

您只需将UITextField 层的masksToBounds 属性显式设置为NO,如下所示:

myTextField.layer.masksToBounds = NO;

【讨论】:

    【解决方案2】:

    试试这个 textField.borderStyle = UITextBorderStyleRoundedRect;

    【讨论】:

      【解决方案3】:

      你可以设置边距:

      myTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 7, 7)];
      

      试试这个

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-02
        • 1970-01-01
        • 1970-01-01
        • 2015-08-07
        • 2013-08-15
        • 1970-01-01
        相关资源
        最近更新 更多