5 Replies Latest reply: Jan 12, 2010 12:16 AM by sommeralex
sommeralex Level 1 Level 1 (10 points)
Hi!

If I am setting a the tintColor to my navigation bar, the effect of "clicking a button" disappears. I still can click the button, but the button does not turn "darker" anymore, when getting clicked.

The same thing happens, if I am adding a custom uiToolbar to my navigation bar. As long as I am not setting the tintColor, the button-press-effect is working..

hm..

macbook air, Mac OS X (10.6.2)
  • draco33333 Level 1 Level 1 (25 points)
    Can you give any code samples?
  • sommeralex Level 1 Level 1 (10 points)
    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]
    initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
    target:self
    action:@selector(bookmark:)];
    saveButton.style = UIBarButtonItemStyleBordered;
    [buttons addObject:saveButton];
    [saveButton release];

    // create a spacer between the buttons
    UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
    target:nil
    action:nil];
    [buttons addObject:spacer];
    [spacer release];

    // create a standard delete button with the trash icon
    UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
    target:self
    action:@selector(magnify:)];
    deleteButton.style = UIBarButtonItemStyleBordered;
    [buttons addObject:deleteButton];
    [deleteButton release];

    // put the buttons in the toolbar and release them
    [toolbar setItems:buttons animated:NO];
    [buttons release];

    // place the toolbar into the navigation bar
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
    initWithCustomView:toolbar];
    [toolbar release];

  • RayNewbie Level 5 Level 5 (6,810 points)
    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.

    \- Ray
  • sommeralex Level 1 Level 1 (10 points)
    thank you for your detailed answer. I will make it with IB.