Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-14-2010, 03:40 AM   #1 (permalink)
Erik Carlson
 
Join Date: Feb 2010
Location: London
Posts: 3
ErikCarlson is on a distinguished road
Default Adding button to left of UISearchBar

Hi All,

I am tearing my hair out on this one. my client wants to add a button to the left of a search bar like the example below:




But I just can't figure out how to do it. Apple don't seem to provide any documented method for adding custom buttons to a UISearchBar, let alone to the left of the search bar.

I've tried hacking around in Interface Builder adding a UIToolbar with a button in it to the left but I cannot find any combination of styles where the two line up properly to give the impression that they are one. there is always what looks like one pixel difference in the vertical alignment as you can see from the picture below:



I've searched around and just can't find the answer, but as we can see from the screenshot it must be possible! I'm hoping someone here has an idea?

Thank you in advance for your help.

Erik
ErikCarlson is offline   Reply With Quote
Old 08-14-2010, 05:29 AM   #2 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 43
split is on a distinguished road
Default

I did this on iPad, but it should work on iPhone too.
Basic idea is to use UIToolbar and add serch bar as UIBarButtonItem. I did it with very customized elements, so I'm not sure if it will work. Let me know.

The code is written straight from my head, so there may be mistakes.

Code:
// button
UIBarButtonItem *settingsButtonItem = // create settings button

// search bar
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 260, 44)];
UIBarButtonItem *searchBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
[searchBar release];

// toolbar is UIToolbar
[toolbar setItems:[NSArray arrayWithObjects:settingsButtonItem, searchBarButtonItem nil] animated:NO];
__________________
Midnight HD Escapology Water Board
split is offline   Reply With Quote
Old 09-16-2010, 05:49 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 1
xwwxy is on a distinguished road
Default i found one way,remove the background of the UISearchBar

for (UIView *subview in searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackg round")]) {
[subview removeFromSuperview];
break;
}
}
xwwxy is offline   Reply With Quote
Reply

Bookmarks

Tags
uisearchbar

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 342
5 members and 337 guests
bignoggins, Chickenrig, givensur, linkmx, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:45 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0