Styling the cancel button in a UISearchBar

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

    Well, here is function, which can change Cancel's button label. Modify it, if you want. Usage is:

    nStaticReplaceStringInView(mySearchBar, @"Cancel", @"NewCancelButtonLabel");
    
    void nStaticReplaceStringInView(UIView * view, NSString * haystack, NSString * needle)
    {
     for(int i=0; i<[view.subviews count]; i++)
     {
      nStaticReplaceStringInView([view.subviews objectAtIndex:i], haystack,needle);
     }
     if([view respondsToSelector:@selector(titleForState:)])
     {
      //NSLog(@"%@ || %@",[view titleForState:UIControlStateNormal], haystack);
      if(NSStrEq([view titleForState:UIControlStateNormal] , haystack))
      {
       [view setTitle: needle forState: UIControlStateNormal];
      }
     }
    }
    

提交回复
热议问题