Custom navigation bar not working on iOS 5

Discussion in 'iOS Programming' started by SimonBS, Jun 7, 2011.

  1. SimonBS, Jun 7, 2011
    Last edited by a moderator: Jun 7, 2011

    SimonBS macrumors regular

    SimonBS

    Joined:
    Dec 30, 2009
    #1
    Hello,

    I just updated my iPhone 3GS to iOS 5 and my Xcode to Xcode 4.3 with SDK 5. I did this to test if my applications are all working properly on iOS 5 and it turns out that my custom navigation bar is not looking correct.

    I have attached two images showing how it is supposed to be (the orange bar from iOS 4.3) and how it is in iOS 5 (the one with the blue navigation bar)

    When running the application I get two errors in the console:

    Code:
    *** ImageIO - could not find ColorSync function 'ColorSyncProfileCreateWithName'
    *** ImageIO - could not find ColorSync function 'ColorSyncProfileCopyData'
    I am not sure what these errors means.

    Here is my code for the custom navigation bar and how I am setting the title on top of it.

    In CustomUINavigationBar.h:

    Code:
    #import <Foundation/Foundation.h>
    
    @interface CustomUINavigationBar : UINavigationBar {
    
    }
    
    @end
    In CustomUINavigationBar.m:

    Code:
    #import "CustomUINavigationBar.h"
    
    @implementation UINavigationBar (CustomImage)
    - (void)drawRect:(CGRect)rect {
        UIImage *image = [UIImage imageNamed:@"UINavigationBar_Background.png"];
        [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    }
    @end
    This is how I add the title in the ViewController.m:

    Code:
    // Setting top title
    [self setTitle:@"Program"];
    UILabel *titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
    [titleView setText:@"Festivalens Program"];
    [titleView setBackgroundColor:[UIColor clearColor]];
    [titleView setFont:[UIFont fontWithName:@"Arial-BoldMT" size:21.0]];
    [titleView setShadowColor:[UIColor colorWithRed:1 green:0.854 blue:0.592 alpha:1]]; // Light orange
    [titleView setShadowOffset:CGSizeMake(0, -1)];
    [titleView setTextAlignment:UITextAlignmentCenter];
    [titleView setTextColor:[UIColor blackColor]];
    [[self navigationItem] setTitleView:titleView];
    [titleView release];
     

    Attached Files:

  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Seems it's trying to do some sort of ColorSync operation (obvious). Can you, perhaps, strip the colour profile from the image in question?
     
  3. SimonBS thread starter macrumors regular

    SimonBS

    Joined:
    Dec 30, 2009
    #3
    Sorry, but I'm not sure what you mean by this. Can you elaborate it? :eek:
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    If im not mistaking, he meant, take the RGB color from the picture, and set it with hand :)
    [UIColor colorWITHRGB something.];
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    The colour profile embedded in the image is used by ColorSync to perform colour matching. As that appears to be the problem removing any colour profile might fix it.

    Try the command-line sips tool with the --deleteColorManagementProperties option...
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    Nope. I'm pretty sure the ColorSync errors prevent the image loading at all so you can't take the colour from it. If the OP tested whether image was nil before drawing I expect it would be.
     
  7. SimonBS thread starter macrumors regular

    SimonBS

    Joined:
    Dec 30, 2009
    #7
    I just tried the following:

    Code:
    Simon-Stvrings-iMac:navigationbar simonstoevring$ sips --deleteColorManagementProperties UINavigationBar_Background.png
    /Users/simonstoevring/Dropbox/Xcode/NibeFestival-2012/resources/NavigationBar/UINavigationBar_Background.png
      /Users/simonstoevring/Dropbox/Xcode/NibeFestival-2012/resources/NavigationBar/UINavigationBar_Background.png
    Simon-Stvrings-iMac:navigationbar simonstoevring$ sips --deleteColorManagementProperties UINavigationBar_Background@2x.png
    /Users/simonstoevring/Dropbox/Xcode/NibeFestival-2012/resources/NavigationBar/UINavigationBar_Background@2x.png
      /Users/simonstoevring/Dropbox/Xcode/NibeFestival-2012/resources/NavigationBar/UINavigationBar_Background@2x.png
    Then I removed the images from my Xcode project and added them again but it makes no difference.
     
  8. SimonBS thread starter macrumors regular

    SimonBS

    Joined:
    Dec 30, 2009
    #8
    I just tried removing my custom navigation bar class (CustomUINavigationBar.m and CustomUINavigationBar.h) from the project but I still get the errors in the console.

     
  9. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #9
    Is anything else not working? If not then perhaps the console messages are not a big problem. Of course that would not explain why your custom nav bar is not working.
     
  10. SimonBS thread starter macrumors regular

    SimonBS

    Joined:
    Dec 30, 2009
    #10
    Well my last tab (the one with three dots and says "Mere") does not working. When pushing it nothing happens. It's just linked to a view controller with a table view. Besides that everything else seems to work.
     
  11. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #11
    You may want to discuss this on the Apple developer forums; remember that iOS 5 is under an NDA.
     
  12. SimonBS thread starter macrumors regular

    SimonBS

    Joined:
    Dec 30, 2009
    #12
  13. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #13
    There are some comments in the release notes about changes regarding categories on UINavBar. In short there's a more compatible way to get a custom appearance for a navbar.
     
  14. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #14
    I said you could ask if it wasn't under NDA. I did not say it was or wasn't, although I specifically said "not iOS 5.0". You then went and posted an issue only occurring on iOS 5.0. I would consider that to be under NDA.
     
  15. SimonBS thread starter macrumors regular

    SimonBS

    Joined:
    Dec 30, 2009
    #15
    Ah, I just checked it.

    But I thought I did subclass the UINavigationBar and override the drawRect: subclass? :confused: Sorry, I'm still a bit green to iOS development.
     
  16. SimonBS thread starter macrumors regular

    SimonBS

    Joined:
    Dec 30, 2009
    #16
    Oh, I'm sorry. I misunderstood you then.
     
  17. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #17
    A category is not a subclass. The apple guys have always said that overriding existing methods in a category is "bad." I understand that if there doesn't seem to be another way and it seems to work with no problems then one may still do "bad" things. But they're still "bad." Anyway, figure out the "good" way to do this.
     
  18. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #18
    Posting parts of the iOS 5.0 documentation is absolutely, 100%, breaking your NDA.
     
  19. mms13 macrumors 6502

    Joined:
    Jun 29, 2010
    Location:
    Baltimore, MD
    #19
    Yeah I noticed this in the Tweetbot app. After I upgraded to iOS 5 beta, their custom navigation bar's color was changed (looks bad now)
     

Share This Page