Custom Navigation Controller functionality.

Discussion in 'iOS Programming' started by SERAPHRowen, Oct 5, 2010.

  1. SERAPHRowen macrumors newbie

    Sep 15, 2010
    I've got an app that uses a UINavigationController. I need some unique behavior, and I turn to you in hopes of a best strategy, as well as letting you know what I've done so far.

    The behavior I need:
    1. Draw a custom background bar image.
    2. Create a secondary image that sits on top of the bar, next to the app title.
    3. Have the secondary image slide in and out along with the text, when the user navigates towards or away from the root view.

    I have 1 and 2 mostly down. 3 I'm struggling with, and it's making me question whether or not my approach with 1 and 2 is sound.

    Here's what I've done to accomplish 1 and 2:
    @implementation UINavigationBar (CustomImage)
    - (void)drawRect:(CGRect)rect
    	UIImage *image = [UIImage imageNamed:@"MyBar.png"];
    	[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height )];
    	DayoAppDelegate* ourDelegate = (DayoAppDelegate*)[[UIApplication sharedApplication] delegate];
    	if( ourDelegate != nil )
    		if( [ourDelegate isInRootView ] == YES )
    			UIImage *logoImage = [UIImage imageNamed:@"MyLogo.png"];
    			[logoImage drawInRect:CGRectMake( (0.28f * self.frame.size.width), (0.05f * self.frame.size.height), 41, 40 )];
    			// Do nothing.
    If anyone could help me with an appropriate strategy, it would be much appreciated. Additionally, is there some way to know whether or not we are on a high resolution device? In cases where I am naming specific pixels such as the above example, it seems like it would be necessary to know that in order to get the correct pixel size.

    Thanks again.
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    You can replace the titleView property of a navigation item. Instead of doing all the complicated stuff that you are doing why not create a UIView, add a UILabel and UIImageView as subviews and set it as the titleView? Then the system will deal with scrolling it left/right on push/pop as needed.
  3. SERAPHRowen thread starter macrumors newbie

    Sep 15, 2010
    That's exactly the light bulb I needed. I knew I was making things harder then they needed to be. Thanks robbieduncan.

Share This Page