UITextField设置backgroundcolor隐藏阴影
所以我用阴影自定义 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]];
阴影被覆盖(被背景颜色隐藏)。
有谁知道如何在文本字段上设置背景颜色和阴影?
So I'm customizing my UITextField.layer with a shadow:
[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)];
This works like a charm but the background is transparent.
Now when I set the background color:
[userNameField.layer setBackgroundColor:[[UIColor whiteColor] CGColor]];
The shadow is overwritten (hidden by the background color).
Does anyone know how to set both the background color AND the shadow on a text field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只需将
UITextField
层的masksToBounds
属性显式设置为 NO,如下所示:You just need to explicitly set the
masksToBounds
property of theUITextField
layer to NO like so:试试这个
textField.borderStyle = UITextBorderStyleRoundedRect;
try this
textField.borderStyle = UITextBorderStyleRoundedRect;
您可以设置边距:
试试这个
You can set margin:
Try this