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

后端 未结 2 2029
梦毁少年i
梦毁少年i 2020-12-16 05:30

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 t

2条回答
  •  星月不相逢
    2020-12-16 05:58

    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
    

提交回复
热议问题