Hor*_*hiv 9 iphone uitextfield uikit uisearchbar
我正试图让UITextField看起来像iPad上的safari应用程序中提供的谷歌搜索字段.该字段的目的是相同的(搜索框).
我知道我可以使用UISearchBar,但我必须使用hackish代码来摆脱放大镜图标和背景,我不希望这样.
我正在使用Apple使用的TextField作为搜索框附加图像.如何修改UITextField以使其外观和行为类似于此屏幕截图中的搜索字段?

我试图修改UITextField的图层roundedCorners属性,但这不能按预期工作.
很感谢任何形式的帮助!
谢谢!
sam*_*sam 17
您可以在任何UIView-Subclass上设置Corner-Radius.
#import <QuartzCore/QuartzCore.h>您的UIViewController子类(您可以在其中访问您选择的UITextfield实例)[yourTextField.layer setCornerRadius:14.0f];Vin*_*kar 10
使用以下代码.它适用于我:
searchField= [[UITextField alloc] initWithFrame:CGRectMake(0,0,150,31)];
searchField.delegate = self;
searchField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
searchField.textColor = [UIColor colorWithRed:102.0/255 green:102.0/255 blue:102.0/255 alpha:1.0];
searchField.textAlignment = UITextAlignmentLeft;
searchField.font = [UIFont fontWithName:@"Helvetica" size:15];
searchField.autocorrectionType = UITextAutocorrectionTypeNo;
searchField.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter;
searchField.clearsOnBeginEditing = NO;
searchField.autocapitalizationType = UITextAutocapitalizationTypeNone;
searchField.autocorrectionType = UITextAutocorrectionTypeNo;
searchField.keyboardType = UIKeyboardTypeURL;
searchField.returnKeyType = UIReturnKeySearch;
searchField.clearButtonMode = UITextFieldViewModeWhileEditing;
searchField.rightViewMode = UITextFieldViewModeUnlessEditing;
searchField.layer.cornerRadius = 17;
searchField.placeholder=@"Google Search";
searchField.borderStyle = UITextBorderStyleRoundedRect;//To change borders to rounded
searchField.layer.borderWidth = 1.0f; //To hide the square corners
searchField.layer.borderColor = [[UIColor grayColor] CGColor]; //assigning the default border color
UIBarButtonItem *searchFieldItem = [[UIBarButtonItem alloc] initWithCustomView:searchField];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14145 次 |
| 最近记录: |