iphone - Right align magnifying glass icon in UISearchBar -


in cocoa-touch find control uisearchbar. need customize search icon (which click performs respective action) present in textfield right aligned. find left aligned. possible so? have done r & d couldn't find ...

how can it? there tutorials can find it?

unfortunately uisearchbar wasn't designed directly support this. in accomplishing want it's we're going have use workarounds compromise visually or functionality wise or write lot of customising code.

i've outlined couple of approaches close want , may of use.

accessing subviews approach

the text within uisearchbar uitextfield subview of uisearchbar , accessible through means i.e. view.subviews.

the magnifying glass search icon uiimageview in leftview property of uitextfield. can switch on right using following code:

// text within uisearchview uitextfield subview of uisearchview. uitextfield *searchfield; (uiview *subview in self.searchbar.subviews) {     if ([subview iskindofclass:[uitextfield class]]) {         searchfield = (uitextfield *)subview;         break;     } }  // icon accessible through 'leftview' property of uitextfield. // set 'rightview' instead. if (searchfield) {     uiview *searchicon = searchfield.leftview;     if ([searchicon iskindofclass:[uiimageview class]]) {         nslog(@"aye");     }     searchfield.rightview = searchicon;     searchfield.leftviewmode = uitextfieldviewmodenever;     searchfield.rightviewmode = uitextfieldviewmodealways; } 

which gives following result:

search bar 1

as can see icon overruns edge of rounded rectangle , clear icon has disappeared. in addition, rightview property intended other content such search results button , bookmarks button. putting search icon here may conflict functionality in way if able use padding of offsets position appropriately.

in least can use approach extract icon uiimageview , position explicitly see fit other view , write custom code handle tap events etc.

customizing appearance approach

in ios v5.0 , later, can customize appearance of search bars using methods listed here. following code makes use of offsets position icon , text within uisearchbar:

[self.searchbar setpositionadjustment:uioffsetmake(255, 0) forsearchbaricon:uisearchbariconsearch]; [self.searchbar setsearchtextpositionadjustment:uioffsetmake(-270, 0)]; 

on standard uisearchbar of 320 width looks following:

search bar 2

this keep event functionality associated icon working expected unfortunately uitextfield confused , despite width, displays small portion of text. if find way allow text display beyond believes end of uitextfield, best bet.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -