How do I change the UISearchbar cancel button's text color

后端 未结 6 1227
醉梦人生
醉梦人生 2020-12-31 18:05

I have a UISearchBar as seen below. How can I change the text color for the cancel button?

\"enter

6条回答
  •  醉话见心
    2020-12-31 18:59

    Gyanerdra's answer works well. But for iOS7 I needed to make the following change for it work in my app.

    NSArray *childViews;
    if ( (APP).isIOS7 ) {
        childViews = [[searchBar.subviews objectAtIndex:0] subviews];
    } else {
        childViews =searchBar.subviews;
    }
    
    for (UIView *subView in childViews ) {
        if([subView isKindOfClass:[UIButton class]]){
            [(UIButton *)subView setTintColor:desiredColor];
            [(UIButton *)subView setTitleColor:desiredColor forState:UIControlStateNormal];
        }
    }
    

    It seems that for iOS7 the search bar is enclosed in a parent view. Hope this helps someone. b

提交回复
热议问题