Mysearchbar. H is as follows:
@ Interface mysearchbar: uisearchbar
-(Void) layoutsubviews;
@ End
Mysearchbar. m is as follows:
# Import "mysearchbar. H"
@ Implementation mysearchbar
-(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
SetBorderStyle: UITextBorderStyleRoundedRect];
UIImage * image = [UIImage
ImageNamed: @ "outposted .png"];
UIImageView * iView = [[UIImageView
Alloc] initWithImage: image];
SearchField. leftView = iView;
}
[Super
LayoutSubviews];
}
@ End
Application:
MySearchBar * searchBar = [MySearchBar alloc] initwitmrm: CGRectMark (10, 10,100, 30)];
SearchBar. backgroundColor = [UIColor
ClearColor]; // modify the background of the search box
SearchBar. showsScopeBar =
NO;
[[SearchBar. subviews
ObjectAtIndex: 0] removeFromSuperview];
// Remove the background from the search box
For (UIView * subview
In searchBar. subviews ){
If ([subview
IsKindOfClass: NSClassFromString (@ "UISearchBarBackground")]) {
[Subview removeFromSuperview];
Break;
}
}
// UIView * baView = [[UIView alloc] init];
// BaView. backgroundColor = [UIColor clearColor];
//
// [SearchBar insertSubview: baView atIndex: 1];