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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -