ios - Change UISearchBar Cancel button to icon -
i want change uisearchbar
's cancel
button 1 has image, , no text. here's got far original behaviour
to this
a step in right direction, problem button wide. when debug view, can see has button label insets of 11 points on left , right. does know how make button fit content size? image square.
here's code customising button:
uibarbuttonitem *barbuttonappearanceinsearchbar; if (ios9) { barbuttonappearanceinsearchbar = [uibarbuttonitem appearancewhencontainedininstancesofclasses:@[[uisearchbar class]]]; } else { barbuttonappearanceinsearchbar = [uibarbuttonitem appearancewhencontainedin:[uisearchbar class], nil]; } barbuttonappearanceinsearchbar.image = [uiimage imagenamed:@"close"]; barbuttonappearanceinsearchbar.title = nil;
another weird issue when dismiss search bar , activate again, button image turns dark (it's still there, can see when debugging views), looks this
any idea how keep icon white? tried method below, without results:
- (void)willpresentsearchcontroller:(uisearchcontroller *)searchcontroller { searchcontroller.searchbar.tintcolor = [uicolor whitecolor]; }
use image rendering , tint color.
barbuttonappearanceinsearchbar.image = [[uiimage imagenamed:@"close"] imagewithrenderingmode:uiimagerenderingmodealwaystemplate]; barbuttonappearanceinsearchbar.tintcolor = [uicolor whitecolor]; barbuttonappearanceinsearchbar.title = nil;
Comments
Post a Comment