可以重写UISearchBar,然后调用layoutSubviews这个方法。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
- ( void )layoutSubviews { UITextField *searchField; NSUInteger numViews = [ self .subviews count ]; for ( int i = 0 ; i < numViews; i++) { if ([[ self .subviews objectAtIndex :i] isKindOfClass :[ UITextField class ]]) { searchField = [ self .subviews objectAtIndex :i]; } } if (!(searchField == nil )) { searchField .textColor = [ UIColor whiteColor ]; [searchField .leftView setHidden : YES ]; [searchField setBackground : [ UIImage imageNamed : @"SearchBarBackground.png" ] ]; [searchField setBorderStyle :UITextBorderStyleNone]; } [ super layoutSubviews ]; } |