How to consolidating the translucency of the navigation bar between iPhone 5S and 5?
Asked Answered
S

2

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?

Stagemanage answered 7/12, 2013 at 1:30 Comment(4)
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.Earthnut
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.Stagemanage
Updating the 5S will make a difference.Ampersand
how to achieve the blur affect as on first top image for ios7.1 ios8? I've created question here #29130345Whereat
V
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.

Vaginectomy answered 7/12, 2013 at 1:38 Comment(4)
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.Stagemanage
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.Earthnut
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".Joettejoey
wtf...changed again in 7.1...but why??? It was good to have the possibility to set the alpha...Blossom
M
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
Mannerless answered 20/3, 2014 at 12:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.