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 09-20-2010, 09:48 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 34
Sachelis is on a distinguished road
Default How do I change a text label on a UIToolbar at runtime?

I’m trying to add a text label on a toolbar in my UIViewController. I first tried adding a UILabel to the view. I can connect it to the File’s Owner from the Interface Builder, but if I position the label on top of the toolbar, it isn’t displayed at runtime.

So I added a UIButtonBarItem with a Plain style (so it displays text but not the button frame). However, Interface Builder won’t let me connect the button item’s “referencing outlet” with the File’s Owner (when I control drag from the button to the xib “panel,” the “File’s Owner” doesn’t highlight and permit a drop).

Any ideas?

Thanks!
Sachelis is offline   Reply With Quote
Old 09-20-2010, 10:43 AM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 32
garyshaf is on a distinguished road
Default

Quote:
Originally Posted by Sachelis View Post
I’m trying to add a text label on a toolbar in my UIViewController. I first tried adding a UILabel to the view. I can connect it to the File’s Owner from the Interface Builder, but if I position the label on top of the toolbar, it isn’t displayed at runtime.

So I added a UIButtonBarItem with a Plain style (so it displays text but not the button frame). However, Interface Builder won’t let me connect the button item’s “referencing outlet” with the File’s Owner (when I control drag from the button to the xib “panel,” the “File’s Owner” doesn’t highlight and permit a drop).

Any ideas?

Thanks!
I use the following code on my Navigation Bar. If you change it to add to your toolbar subview, it should work:

Code:
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0,0,10,10)] autorelease];
	label.textColor = [UIColor whiteColor];
	label.backgroundColor =[UIColor clearColor]; 
	label.font = [UIFont fontWithName:@"Verdana" size:16.0];
	self.navigationItem.titleView = label;
	label.text = @"Your Text";
	[label sizeToFit];
garyshaf is offline   Reply With Quote
Old 09-20-2010, 04:42 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 34
Sachelis is on a distinguished road
Default

Quote:
Originally Posted by garyshaf View Post
I use the following code on my Navigation Bar. If you change it to add to your toolbar subview, it should work:

Code:
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0,0,10,10)] autorelease];
	label.textColor = [UIColor whiteColor];
	label.backgroundColor =[UIColor clearColor]; 
	label.font = [UIFont fontWithName:@"Verdana" size:16.0];
	self.navigationItem.titleView = label;
	label.text = @"Your Text";
	[label sizeToFit];
Thanks Gary. Your your code is changing the titleView of a navigation bar, whereas I have a toolbar which is a different critter. I can access self.toolbarItems. I suspect there is a way to cycle through the toolbarItems and locate my button to change its text.
Sachelis is offline   Reply With Quote
Old 09-20-2010, 05:37 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 34
Sachelis is on a distinguished road
Default

<blush> I found that I could add a UILabel to the view and have it appear on top of the toolbar. When I previously tried, I positioned the UILabel too low on the view and it was being covered by the tab control.

A side note, in case somebody ends up on this thread trying to modify objects on a toolbar: you can add a UIToolbar variable to your view class, connect the toolbar to the variable, and then access the objects in your toolbar (you can also see the objects in the debugger). However, I wasn't able to change the titles at runtime, but this is handy for other purposes.

Code:
NSArray *buttonBarItems = self.myToolbar.items;
UIBarItem *pButton = [buttonBarItems objectAtIndex:2];
Sachelis is offline   Reply With Quote
Reply

Bookmarks

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: 314
14 members and 300 guests
2ndSegment, cayladv57, cgokey, dermotos, djohnson, Domele, Hamad, linkmx, markuschow, pungs, Sloshmonster, teebee74, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

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