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

百般思念 提交于 2019-11-29 02:28:30

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.

Karim

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!