Styling the cancel button in a UISearchBar

前端 未结 21 1374
-上瘾入骨i
-上瘾入骨i 2020-12-02 09:13

I have a UISearchBar that has a cancel button (it\'s displayed using -(void)setShowsCancelButton:animated). I\'ve changed the tintColor of the sear

21条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 09:51

    - (void) searchBarTextDidBeginEditing:(UISearchBar *)theSearchBar 
    {        
        NSArray *arr = [theSearchBar subviews];
        UIButton *cancelButton = [arr objectAtIndex:3];
        [cancelButton setTitle:@"yourtitle" forState:UIControlStateNormal];    
    }
    

    Just take a log of arr amd see at which index control lies. In the same way u can set UITextField properties:

        NSArray *arr = [searchbar subviews];
        UITextField *searchfield = [arr objectAtIndex:2];
        [searchfield setTextAlignment:UITextAlignmentRight];
    

提交回复
热议问题