6

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?

Pwner
  • 3,714
  • 6
  • 41
  • 67
  • 1
    Both devices are running iOS7, but are they running the same iOS7 version? Changes were made to iOS 7.0.3 and further changes have been made in iOS 7.1 beta 1. – Léo Natan Dec 07 '13 at 01:32
  • The 5S is on 7.0.2. The 5 is on iOS 7.0.4. I'll upgrade the 5S now and see if it makes a difference. – Pwner Dec 07 '13 at 01:36
  • Updating the 5S will make a difference. – Aaron Brager Dec 07 '13 at 01:36
  • how to achieve the blur affect as on first top image for ios7.1 ios8? I've created question here http://stackoverflow.com/questions/29129845/uinavigationbar-blur-ios-7-1-and-above – Matrosov Oleksandr Mar 18 '15 at 19:04

2 Answers2

4

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.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • Yeah, that was the problem. In iOS 7.0.4, the alpha value is respected. Such a pity that everyone will view my app differently. – Pwner Dec 07 '13 at 01:50
  • 4
    To add salt to the injury, Apple has modified the algorithm once again in iOS 7.1 beta. I suggest you update one of your development devices and compile using 7.1 SDK to see if your app still looks well there. – Léo Natan Dec 07 '13 at 01:52
  • Confirmed. It is changed again in 7.1. What a shame, so basically just few users that stayed on 7.0.3 - 7.0.6 have alpha value "working". – czaku Mar 12 '14 at 13:22
  • wtf...changed again in 7.1...but why??? It was good to have the possibility to set the alpha... – LombaX Mar 12 '14 at 18:52
3

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
Community
  • 1
  • 1
Karim
  • 766
  • 7
  • 9