UISearchBar的使用心得
UISearchBar是无法修改其 textField的大小的
http://stackoverflow.com/questions/556814/changing-the-size-of-the-uisearchbar-textfield
The text field used in UISearchBar is a subclass of UITextField called UISearchBarTextField.
AFAIK, there's no way to resize a UISearchBarTextField using the public API, and the private APIdoesn't reveal much either.
Maybe you can take a look at UISearchBarTextField's subviews, if it has any.
- (void)layoutSubviews {
UITextField *searchField;
NSUInteger numViews = [self.subviews count];
for(int i = 0; i < numViews; i++) {
if([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) { //conform?
searchField = [self.subviews objectAtIndex:i];
}
}
if(!(searchField == nil)) {
searchField.textColor = [UIColor redColor];
// [searchField setBackground: [UIImage imageNamed:@"esri.png"] ];
[searchField setBorderStyle:UITextBorderStyleRoundedRect];
UIImage *image = [UIImage imageNamed: @"esri.png"];
UIImageView *iView = [[UIImageView alloc] initWithImage:image];
searchField.leftView = iView;
[iView release];
}
[super layoutSubviews];
}
// 设置搜索栏输入框形状
UITextField *searchField = nil;
for (UIView *subview in searchBar.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
searchField = (UITextField *)subview;
break;
}
}
if (searchField) {
searchField.borderStyle = UITextBorderStyleRoundedRect;
}
// 设置搜索栏输入框边框颜色
searchField.layer.cornerRadius = 8.0f;
searchField.layer.masksToBounds = YES;
searchField.layer.borderColor = [[UIColor colorWithRed:118.0f/255.0f green:193.0f/255.0f blue:220.0f/255.0f alpha:1.0f]CGColor];
searchField.layer.borderWidth = 2.0f;
浙公网安备 33010602011771号