3698 Views 5 Replies Latest reply: Jan 12, 2010 12:16 AM by sommeralex
The code example is below.. I made a screenshot when I was clicking the button (the curser is not shown in the screenshot) - and there is no button select effect.
Hence, it seems that the UIToolBar is not drawn properly. There remains a white line at the top and bottom, see here: http://www.learnclip.com/iPhoneDev/uitoolbar.png. If I am changing the height from 45 to 44, it looks like this: http://www.learnclip.com/iPhoneDev/uitoolbar2.png
UIToolbar* toolbar = [[UIToolbar alloc]
initWithFrame:CGRectMake(0, 0, 100, 45)];
[toolbar setTintColor:[[UIColor alloc] initWithRed:150.0 green:0.0 blue:0.0 alpha:1]];
// create an array for the buttons
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// create a standard save button
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]
saveButton.style = UIBarButtonItemStyleBordered;
// create a spacer between the buttons
UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
// create a standard delete button with the trash icon
UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc]
deleteButton.style = UIBarButtonItemStyleBordered;
// put the buttons in the toolbar and release them
[toolbar setItems:buttons animated:NO];
// place the toolbar into the navigation bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
Hi Alex -
I played with tints and bars in the attempt to answer a similar question recently posted by Luther Baker: [http://discussions.apple.com/message.jspa?messageID=10829363#10829363]. I was unable to do what Luther needed in my testbed, but you only need the first half of his requirements, so I may have learned enough to help.
Firstly, I discovered that applying a tint in IB would work correctly for both nav and tool bars. However for some reason, if I set the tint programmatically in viewDidLoad, the tool bar controls no longer displayed the highlight (darker) color correctly. I don't remember doing the same test on a nav bar, but I can tell you that getting custom controls to pick up the bar tint is much easier with a nav bar.
The next question is, "At what point in the life cycle of a tool bar should it be tinted?". I didn't get far enough to answer that, and being clueless about the mechanism didn't help. It might be that the tint needs to be set before the controls are added, and/or before the bar is added to the superview, but I haven't yet tried all the possibilities.
So my short answer is: Make the toolbar with its controls and add it to the content view in IB. That might exclude using the toolbar that belongs to a nav controller.
If you must build the toolbar programmatically, someone will need to find the correct point in the creation and load sequence to set the tint. Hopefully I can find my BarTint testbed if further research is necessary.