Styling the cancel button in a UISearchBar

前端 未结 21 1427
-上瘾入骨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:59

    UISearchBar *searchBar;
    [searchBar setShowsCancelButton:YES animated:YES];
    
    UIButton *cancelButton = 
    YES == [searchBar respondsToSelector:NSSelectorFromString(@"cancelButton")] ? 
    [searchBar valueForKeyPath:@"_cancelButton"] : nil;
    
    cancelButton.titleEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10);
    [cancelButton setTitle:@"New :)" forState:UIControlStateNormal];
    

提交回复
热议问题