iOS 7 UIBarButton back button arrow color

后端 未结 17 1888
情话喂你
情话喂你 2020-12-04 06:30

I\'m trying to change the back button arrow

\"enter

I\'m currently using the

相关标签:
17条回答
  • 2020-12-04 06:42

    If you want to change only the Back Arrow BUT on the entire app, do this:

    [[NSClassFromString(@"_UINavigationBarBackIndicatorView") appearance] 
      setTintColor:[UIColor colorWithHexString: @"#f00000"]];
    
    0 讨论(0)
  • 2020-12-04 06:43

    If you are using storyboards you could set the navigation bar tint colour.

    0 讨论(0)
  • 2020-12-04 06:43

    In iOS 7, you can put the following line of code inside application:didFinishLaunchingWithOptions: in your AppDelegate.m file:

    [[UINavigationBar appearance] setTintColor:myColor];
    

    Set myColor to the color you want the back button to be throughout the entire app. No need to put it in every file.

    0 讨论(0)
  • 2020-12-04 06:43

    In swift 3 , to change UIBarButton back button arrow color

    self.navigationController?.navigationBar.tintColor = UIColor.black
    
    0 讨论(0)
  • 2020-12-04 06:44

    In case you're making custom back button basing on UIButton with image of arrow, here is the subclass snippet. Using it you can either create button in code or just assign class in Interface Builder to any UIButton. Back Arrow Image will be added automatically and colored with text color.

    @interface UIImage (TintColor)
    
    - (UIImage *)imageWithOverlayColor:(UIColor *)color;
    
    @end
    
    
    @implementation UIImage (TintColor)
    
    - (UIImage *)imageWithOverlayColor:(UIColor *)color
    {
        CGRect rect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height);
    
        if (UIGraphicsBeginImageContextWithOptions) {
            CGFloat imageScale = 1.0f;
            if ([self respondsToSelector:@selector(scale)])
                imageScale = self.scale;
            UIGraphicsBeginImageContextWithOptions(self.size, NO, imageScale);
        }
        else {
            UIGraphicsBeginImageContext(self.size);
        }
    
        [self drawInRect:rect];
    
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetBlendMode(context, kCGBlendModeSourceIn);
    
        CGContextSetFillColorWithColor(context, color.CGColor);
        CGContextFillRect(context, rect);
    
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return image;
    }
    
    @end
    
    
    
    
    #import "iOS7backButton.h"
    
    @implementation iOS7BackButton
    
    -(void)awakeFromNib
    {
        [super awakeFromNib];
    
        BOOL is6=([[[UIDevice currentDevice] systemVersion] floatValue] <7);
        UIImage *backBtnImage = [[UIImage imageNamed:@"backArrow"] imageWithOverlayColor:self.titleLabel.textColor];
        [self setImage:backBtnImage forState:UIControlStateNormal];
        [self setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
        [self setImageEdgeInsets:UIEdgeInsetsMake(0, is6?0:-10, 0, 0)];
    
    
    }
    
    
    + (UIButton*) buttonWithTitle:(NSString*)btnTitle andTintColor:(UIColor*)color {
        BOOL is6=([[[UIDevice currentDevice] systemVersion] floatValue] <7);
        UIButton *backBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
        UIImage *backBtnImage = [[UIImage imageNamed:@"backArrow"] imageWithOverlayColor:color];
        [backBtn setImage:backBtnImage forState:UIControlStateNormal];
        [backBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, is6?5:-5, 0, 0)];
        [backBtn setImageEdgeInsets:UIEdgeInsetsMake(0, is6?0:-10, 0, 0)];
        [backBtn setTitle:btnTitle forState:UIControlStateNormal];
        [backBtn setTitleColor:color /*#007aff*/ forState:UIControlStateNormal];
    
        return backBtn;
    }
    
    @end
    

    back button image@2x

    0 讨论(0)
  • 2020-12-04 06:49
    UINavigationBar *nbar = self.navigationController.navigationBar;
    
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
       //iOS 7
       nbar.barTintColor = [UIColor blueColor]; // bar color
       //or custom color 
       //[UIColor colorWithRed:19.0/255.0 green:86.0/255.0 blue:138.0/255.0 alpha:1];
    
       nbar.navigationBar.translucent = NO;
    
       nbar.tintColor = [UIColor blueColor]; //bar button item color
    
    } else {
       //ios 4,5,6
       nbar.tintColor = [UIColor whiteColor];
       //or custom color
       //[UIColor colorWithRed:19.0/255.0 green:86.0/255.0 blue:138.0/255.0 alpha:1];
    
    }
    
    0 讨论(0)
提交回复
热议问题