The usage of Uisearchcontroller after iOS8

Source: Internet
Author: User

Looked at a lot of information, not too full, I looked at the Apple document, wrote a code: The following (just interface):

1. Declare the attribute @property (nonatomic, strong) Uisearchcontroller *searchcontroller;

2. Calling method: [self searchcontroller];

3. Implementation:-(Uisearchcontroller *) Searchcontroller {
if (!_searchcontroller) {
_searchcontroller = [[Uisearchcontroller alloc] initwithsearchresultscontroller:nil];
Searchbar
_searchcontroller.searchbar.frame = CGRectMake (0, 0, kWidth-40, 36);
_searchcontroller.searchbar.placeholder = @ "Search";
_searchcontroller.searchbar.bartintcolor = [Uicolor colorwithred:1.00f green:0.62f blue:0.45f alpha:1.00f];
Searchbartextfield
Uitextfield *searchfield = nil;
Searchfield = [[_searchcontroller.searchbar.subviews objectatindex:0].subviews Lastobject];
Searchfield.backgroundcolor = [Uicolor colorwithred:1.00f green:0.62f blue:0.45f alpha:1.00f];
Uicolor *color = [Uicolor Whitecolor];
Searchfield.attributedplaceholder = [[Nsattributedstring alloc] initwithstring:@ "You can also enter keyword search" attributes:@{ Nsforegroundcolorattributename:color}];


_searchcontroller.view = [[UIView alloc] Initwithframe:cgrectmake (352/2, kWidth-40, 36)];
[_searchcontroller.view Addsubview:_searchcontroller.searchbar];
_searchcontroller.view.backgroundcolor = [Uicolor colorwithred:1.00f green:0.62f blue:0.45f alpha:1.00f];
[Self.tableheaderview AddSubview:self.searchController.view];
}
return _searchcontroller;
}

4. View the effect:

The usage of Uisearchcontroller after iOS8

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.