Question

I have difficulty consolidating the UINavigationBar's barTintColor between iPhone 5 and 5S. Both of my phones are on iOS 7. In the following screenshot, the top is 5S and the bottom is 5. iPhone 5S shows an extremely translucent effect while iPhone 5 shows a much more subtle effect. Only very dark objects are visible behind the navigation bar for iPhone 5.

[[UINavigationBar appearanceWhenContainedIn:[UINavigationController class], nil]
    setBarTintColor:[UIColor 
        colorWithRed:46.0 / 255.0 
        green:160.0 / 255.0 
        blue:152.0 / 255.0 
        alpha:0.8
    ]
];

enter image description here

I would prefer that both phones look like the iPhone 5. If I were to increase the alpha of the barTintColor to 1.0, iPhone 5's navigation bar would become completely opaque. This is the expected result. Although iPhone 5S's bar would become less translucent, the effect is still too strong. How would I decrease the translucency even more, without making it completely opaque?

Was it helpful?

Solution

As discussed in the comments, you are seeing different behaviors because one of the devices is using an outdate iOS 7 version. Apple made changes in version 7.0.3 to the way bar tint color is processed, and now the alpha value is taken into account. You should focus on the newer version of iOS.

OTHER TIPS

if you still want to set the alpha for your navigation bar in IOS 7.1 I found a workaround to do it. Create an image from a colour with alpha set for it, then assign this image as a background to the navigation bar:

1- here is the method to create an image from colour:

    -(UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

i found it at: Creating a UIImage from a UIColor to use as a background image for UIButton

//create a colour and set its alpha:

UIColor *colorWithAlpha = [UIColor colorWithRed:(80/255.f) green:(146/255.f) blue:(84/255.f) alpha:0.2]; // light red colour

// create your background image:
UIImage *backgroundImage = [self imageWithColor: colorWithAlpha];

//set this image as a background image:    
[self.navigationController.navigationBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];

self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init]; // to remove shadow
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top