How to customize appearance of UISearchBar

后端 未结 9 1791
盖世英雄少女心
盖世英雄少女心 2020-12-04 09:53

I want to customize the search bar, I mean the white box. Can I do it? Is there some documentation about that? Is there a way to hide the white box, but not the letters. Can

9条回答
  •  执笔经年
    2020-12-04 10:17

    // Search Bar Customization
    // Background Image
    [self.searchDisplayController.searchBar setBackgroundImage:[[UIImage alloc]init]];
    
    // Backgroud Color
    [self.searchDisplayController.searchBar setBackgroundColor:[UIColor redColor]];
    
    // Search Bar Cancel Button Color
    [[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor whiteColor]];
    
    // set Search Bar Search icon
    [self.searchDisplayController.searchBar setImage:[UIImage imageNamed:@"search_ico.png"]
                                    forSearchBarIcon:UISearchBarIconSearch
                                               state:UIControlStateNormal];
    
    // set Search Bar textfield background image
     [[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:@"search_box.png"]
                                                    forState:UIControlStateNormal];
    
    // set Search Bar texfield corder radius
    UITextField *txfSearchField = [self.searchDisplayController.searchBar valueForKey:@"_searchField"];
    txfSearchField.layer.cornerRadius = 10.8f;
    

提交回复
热议问题