iOS - Customizing Cancel button of UISearchBar

后端 未结 4 2262
我在风中等你
我在风中等你 2020-12-14 22:16

In my iOS5 iPhone application, i\'m setting the tint color of search bar using following code:

searchBar.tintColor = UIColorMake(@\"#EFEFEF\");
4条回答
  •  温柔的废话
    2020-12-14 23:21

    You could search for UISearchBar subViews and locate the cancel button, it is dangerous to do so, since the button could change For example you could add this in your viewWillAppear

    - (void) viewWillAppear:(BOOL)animated
    {
        //show the cancel button in your search bar
        searchBar.showsCancelButton = YES;
        //Iterate the searchbar sub views
        for (UIView *subView in searchBar.subviews) {
            //Find the button
            if([subView isKindOfClass:[UIButton class]])
            {
                //Change its properties
                UIButton *cancelButton = (UIButton *)[sb.subviews lastObject];
                cancelButton.titleLabel.text = @"Changed";
            }
        }
    }
    

    As i said before this could change, its a hack to do so, you better stick with the original, or create your own search bar.

提交回复
热议问题