Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Change UISearchBar appearance in Objective C

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 679
    Comment on it

    If you want to change the appearance of UISearchBar and its related elements then use below code.

    -(void)changeSearchBarAppearance{
    
        [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setBackgroundColor:[UIColor whiteColor]];
        UITextField *searchField;
        NSUInteger numViews = [_searchBar.subviews count];
        for(int i = 0; i < numViews; i++) {
            if([[_searchBar.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) { //conform?
                searchField = [_searchBar.subviews objectAtIndex:i];
            }
        }
        if(!(searchField == nil)) {
            searchField.textColor = [UIColor whiteColor];
            [searchField setBackground: [UIImage imageNamed:@"yourImage"]];//just add here gray image which you display in quetion
            [searchField setBorderStyle:UITextBorderStyleNone];
        }
    
    }
    

    Happy Coding!!!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: