How to customize appearance of UISearchBar

后端 未结 9 1790
盖世英雄少女心
盖世英雄少女心 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:19

    Here is the solution I was looking for: Subclassing a UISearchBar, & overwriting the method layoutSubviews

    - (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 whiteColor];
           [searchField setBackground: [UIImage imageNamed:@"buscador.png"] ];
           [searchField setBorderStyle:UITextBorderStyleNone];
       }
    
       [super layoutSubviews];
    }
    

提交回复
热议问题