IOS Development Uisearchbar Custom Look __ios

Source: Internet
Author: User
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: @ "departure location. png"];

Uiimageview *iview = [[Uiimageview alloc] initwithimage:image];

Searchfield.leftview = IView;

}

[Super Layoutsubviews];

}

@end



Application:

Mysearchbar *searchbar = [Mysearchbar alloc] Initwithrct:cgrectmark (10, 10, 100,30)];

Searchbar.backgroundcolor = [Uicolor Clearcolor]; Modify the search box background

Searchbar.showsscopebar = NO;

[[Searchbar.subviews Objectatindex:0]removefromsuperview]; Remove the background of 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];

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.