我创建了NSObject的CommonMethod子类来自定义UINavigationBar,这里是CommonMethod.h和CommonMethod.m文件
通用方法
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface CommonMethods : NSObject
+(void)setNavBackButton:(id)viewController;
+(void)setNavBackground:(id)viewController Color:(UIColor *)color;
@end
通用方法
#import <UIKit/UIKit.h>
#import "CommonMethods.h"
@implementation CommonMethods
+(void)setNavBackground:(id)viewController Color:(UIColor *)color
{
UIViewController *controller = (id)viewController;
controller.navigationController.navigationBar.backgroundColor=[UIColor redColor];
}
@end
现在,当我调用
[CommonMethods setNavBackground:self Color:[UIColor redColor];
时,它正在执行该方法,但未更改UI上的任何内容。任何人都可以解释我所缺少的吗?编辑:
我也试过
controller.navigationController.navigationBar.barTintColor = color;
最佳答案
您对代码有轻微的错误
+(void)setNavBackground:(id)viewController Color:(UIColor *)color
{
UIViewController *controller = (id)viewController;
controller.navigationController.navigationBar.barTintColor = color; // Change NavigationBar color to Red
}
调用方法如下:[CommonMethod setNavBackground:self Color:[UIColor redColor]];