Uisearchbar and examples of IOS development _ios

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.