Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying UISearchBar Cancel button font text color and style

Tags:

Is there any way to change the text font and color of the UISearchBar Cancel button without subclassing the searchbar?

like image 948
Rowie Po Avatar asked Jul 20 '12 03:07

Rowie Po


Video Answer


1 Answers

You can change Cancel button styling by changing the appearance of UIBarButtonItem when contained in UISearchBar.

For example,

[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:                                                       [UIColor blueColor],                                                        UITextAttributeTextColor,                                                        [UIColor darkGrayColor],                                                        UITextAttributeTextShadowColor,                                                        [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],                                                        UITextAttributeTextShadowOffset,                                                       nil]                                              forState:UIControlStateNormal]; 
like image 128
htinlinn Avatar answered Sep 21 '22 05:09

htinlinn