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

enter image description here

to this

enter image description here

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

enter image description here

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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -