我正在尝试更改导航栏后退按钮文本的文本。我已经尝试过这里提供的解决方案,但无法在“后退”按钮上得到想要的文本。在appdelegate中,我设置了以下功能:
[[UINavigationBar appearance] setBarTintColor:[self colorWithHexString:@"e74c3c"]];
[[UINavigationBar appearance] setBarTintColor:[self colorWithHexString:@"e74c3c"]];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont fontWithName:@"Futura-CondensedMedium" size:19.0], UITextAttributeFont,nil]];
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowOffset = CGSizeMake(0.0, 1.0);
shadow.shadowColor = [UIColor whiteColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor whiteColor],
NSShadowAttributeName:shadow,
NSFontAttributeName:[UIFont fontWithName:@"Futura-CondensedMedium" size:19.0]
}
forState:UIControlStateNormal];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
在每个viewcontroller中,viewdidload
我都设置了:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"SomeText" style:UIBarButtonItemStylePlain target:nil action:nil];
或者
UIBarButtonItem *newBackButton =
[[UIBarButtonItem alloc] initWithTitle:@"NewTitle"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[[self navigationItem] setBackBarButtonItem:newBackButton];
有什么建议?
如果我没有误会,您可以执行此操作以设置后退按钮的标题。假设有三个视图控制器:A
,B
和C
。现在,当您从导航A
到时,您希望后退按钮的标题为“ MyViewA” ,B
然后需要将此代码放在ViewController的“ viewWillAppear:”中A
(当您将后退按钮的标题显示为“ MyViewA”时,在视图控制器上B
)。
//viewWillAppear of ViewController A
-(void)viewWillAppear:(BOOL)animated{
//now set title of back button
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@"YourTitle"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
}
同样,如果您要导航B
至C
并希望为ViewController设置后退按钮标题C
,则需要将以上代码放入ViewController的“ viewWillAppear:”委托中B
。简而言之,您需要在当前视图控制器上设置下一个视图控制器的标题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句