我在每个 ViewController 中都有相同的代码,它设置 ViewControllers 视图的背景颜色,并更改导航栏的后退按钮和标题视图。有没有办法避免这种情况?
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 37, 24)];
[button setImage:[UIImage imageNamed:@"Navbar_BackButton.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(backButtonTabbed:) forControlEvents:UIControlEventTouchDown];
[button setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
[navbarItem setLeftBarButtonItem:barButton];
[navbarItem setTitleView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Navbar_Title.png"]]];
[[self view] setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Login_Background.png"]]];