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

后端 未结 6 1229
醉梦人生
醉梦人生 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:54

    You can take advantage of the iOS Runtime Property _cancelButton to achieve this.

    UIButton *cancelButton = [searchBar valueForKey:@"_cancelButton"];
    [cancelButton setTitleColor:[UIColor yourColor] forState:UIControlStateNormal];
    

    Unable to change UISearchBar cancel button title color after changing it's text.

提交回复
热议问题