如何制作更圆润的UITextField?就像iPad上Safari中的搜索字段一样 [英] How can i make a more rounded UITextField? Like the search field in Safari on iPad
问题描述
我想让一个UITextField看起来像iPad上的safari应用程序中提供的谷歌搜索字段。该字段的目的是相同的(搜索框)。
HI I'm trying to get a UITextField to look like the google search field available in the safari app on iPad. The purpose of the field will be the same (a search box).
我知道我可以使用UISearchBar但我必须使用hackish代码来摆脱放大镜图标和背景,我不希望这样。
I know i could use a UISearchBar but I would have to use hackish code to get rid of the magnifying glass icon and the background and I don't want that.
我附加了一个图像,其中Apple使用的TextField作为搜索框。如何修改UITextField以使其外观和行为类似于此屏幕截图中的搜索字段?
I'm attaching an image with the TextField used by apple as their search box. How can I modify an UITextField to look and behave like the search field in this screenshot?
我试过修改了UITextField的图层roundedCorners属性,但这不能按预期工作。
I tried to modified the UITextField's layer roundedCorners property but this doesn't work as expected.
非常感谢任何帮助!
谢谢!
推荐答案
您可以在任何UIView-Subclass上设置Corner-Radius。
You can set the Corner-Radius on any UIView-Subclass.
- 将QuartzCore.framework添加到项目中
- 添加
#import< QuartzCore / QuartzCore.h> ;
在你的UIViewController子类中(你可以访问你选择的UITextfield实例) - 在viewDidLoad / viewWillAppear中(或者你的UITextfield已经实例化的任何其他地方)调用
[yourTextField.layer setCornerRadius:14.0f];
- 使用cornerRadius值,直到看起来不错
- Add the QuartzCore.framework to your project
- add
#import <QuartzCore/QuartzCore.h>
in your UIViewController Subclass (where you have access to the UITextfield instance of your choice - within viewDidLoad / viewWillAppear (or any other place where your UITextfield is allready instantiated call
[yourTextField.layer setCornerRadius:14.0f];
- play around with the cornerRadius value until it looks good
这篇关于如何制作更圆润的UITextField?就像iPad上Safari中的搜索字段一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!