Styling the cancel button in a UISearchBar

前端 未结 21 1372
-上瘾入骨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 10:08

    You can find the cancel button by looping through the subviews of the search bar and checking for the class type (instead of the size):

    UIButton *cancelButton = nil;
    for(UIView *subView in yourSearchBar.subviews){
        if([subView isKindOfClass:UIButton.class]){
        cancelButton = (UIButton*)subView;
        }
    }
    

    And then change the tint color:

    [cancelButton setTintColor:[UIColor colorWithRed:145.0/255.0 green:159.0/255.0 blue:179.0/255.0 alpha:1.0]];
    

提交回复
热议问题