IOS Uisearchbar Detailed
The development of the iphone Uisearchbar learning is to learn the content of this article, mainly introduced the use of Uisearchbar, not to say, we first look at the detailed content. Some questions about the Uisearchbar.
1, modify the background color of Uisearchbar
Uisearchbar is made up of two subview, one is Uisearchbarbackground and the other is Uitextfield. To IB there are no properties that directly manipulate the background. The method is to move the uisearchbarbackground directly.
Seachbar=[[uisearchbar alloc] init];
Seachbar.backgroundcolor=[uicolor Clearcolor];
For (UIView *subview in seachbar.subviews)
{
if (Subview iskindofclass:nsclassfromstring (@) Uisearchbarbackground ")])
{
[subview Removefromsuperview];
break;
}
}
The second way to solve this problem is:
2,
uisearchbar* M_searchbar = [[Uisearchbar alloc] Initwithframe:cgrectmake (0, O, MB)];
M_searchbar.delegate = self;
M_searchbar.barstyle = uibarstyleblacktranslucent;
M_searchbar.autocorrectiontype = Uitextautocorrectiontypeno;
M_searchbar.autocapitalizationtype = Uitextautocapitalizationtypenone;
M_searchbar.placeholder = _ (@ "Search");
M_searchbar.keyboardtype = Uikeyboardtypedefault;
Add a background picture to Uisearchbar
uiview *segment = [M_searchbar.subviews objectatindex:0];
Uiimageview *bgimage = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@ "Images/search_bar_bg.png"]];
[Segment Addsubview:bgimage];
<---background picture
[Self.view Addsubview:m_searchbar];
[M_searchbar release];
3: Cancel the keyboard called by Uisearchbar
Two ways to add Uisearchbar:
Code
Uisearchbar *mysearchbar = [[Uisearchbar alloc]
initwithframe:cgrectmake (0.0, 0.0, self.view.bounds.size.width, )];
Mysearchbar.delegate = self;
Mysearchbar.showscancelbutton = NO;
Mysearchbar.barstyle=uibarstyledefault;
mysearchbar.placeholder=@ "Enter Name or categary";
Mysearchbar.keyboardtype=uikeyboardtypenamephonepad;
[Self.view Addsubview:mysearchbar];
[Mysearchbar release];
Add on TableView:
Code
//add Table UITableView *mybeaconstableview = [[UITableView alloc]
Initwithframe:cgrectmake (0, 0, self.view.bounds.size.width, self.view.bounds.size.height-40)
Style:uitableviewstyleplain];
Mybeaconstableview.backgroundcolor = [Uicolor Whitecolor];
mybeaconstableview.delegate=self;
mybeaconstableview.datasource=self;
[Mybeaconstableview setrowheight:40]; ADD Searchbar searchbar = [[Uisearchbar alloc] initwithframe:cgrectmake (0.0, 0.0, self.view.bounds.size.width, 40
)];
searchbar.placeholder=@ "Enter Name";
Searchbar.delegate = self;
Mybeaconstableview.tableheaderview = Searchbar;
Searchbar.autocorrectiontype = Uitextautocorrectiontypeno;
Searchbar.autocapitalizationtype = Uitextautocapitalizationtypenone;
[Searchbar release];
[Self.view Addsubview:mybeaconstableview];
[Mybeaconstableview release];
Summary: iphone development Uisearchbar Learning content, I hope this article is helpful to you