当 backBarButtonItem 有长文本时显示“...”
Display "..." when backBarButtonItem have long text
我是 iOS 编程的新手。我使用应用 导航栏 ,并为 后退 按钮设置文本,如下所示:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"my text" style:UIBarButtonItemStyleBordered target:nil action:nil];
它工作正常。但是,当我的文本很长时会出现问题,backBarButtonItem 显示默认文本是 Back。
所以,问题是:如何在 backBarButtonItem 中显示长文本,也许显示“...”而不是全文。或者我可以使用自定义视图替换默认导航栏吗?
P/s : 我已经参考了 "back" text displayed in iOS7 UINavigationBar when view title is long 但它对我解决这个问题没有帮助。
试试这个
self.navigationItem.hidesBackButton = YES;
UIButton *btnLeft=[UIButton buttonWithType:UIButtonTypeCustom];
btnLeft.frame=CGRectMake(0, 0, button.widh, button.height);
[btnLeft addTarget:self action:@selector(onClickBackBarItem:) forControlEvents:UIControlEventTouchUpInside];
[btnLeft setTitle:@"YOUR TEXT" forState:UIControlStateNormal];
btnLeft.titleLabel.font = [UIFont fontWithName:@"font_name" size:25.0];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];
希望对您有所帮助
使用 sizeToFit
在 UIButton
中显示全文
UIButton *btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 20) ];
[btnBack setTitle:@"Skip" forState:UIControlStateNormal];
btnBack.titleLabel.font = [UIFont fontWithName:@"SFUIText-Medium" size:15];
[btnBack sizeToFit];
[btnBack addTarget:self action:@selector(backActionEvent:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnSkip];
我是 iOS 编程的新手。我使用应用 导航栏 ,并为 后退 按钮设置文本,如下所示:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"my text" style:UIBarButtonItemStyleBordered target:nil action:nil];
它工作正常。但是,当我的文本很长时会出现问题,backBarButtonItem 显示默认文本是 Back。
所以,问题是:如何在 backBarButtonItem 中显示长文本,也许显示“...”而不是全文。或者我可以使用自定义视图替换默认导航栏吗?
P/s : 我已经参考了 "back" text displayed in iOS7 UINavigationBar when view title is long 但它对我解决这个问题没有帮助。
试试这个
self.navigationItem.hidesBackButton = YES;
UIButton *btnLeft=[UIButton buttonWithType:UIButtonTypeCustom];
btnLeft.frame=CGRectMake(0, 0, button.widh, button.height);
[btnLeft addTarget:self action:@selector(onClickBackBarItem:) forControlEvents:UIControlEventTouchUpInside];
[btnLeft setTitle:@"YOUR TEXT" forState:UIControlStateNormal];
btnLeft.titleLabel.font = [UIFont fontWithName:@"font_name" size:25.0];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];
希望对您有所帮助
使用 sizeToFit
在 UIButton
中显示全文
UIButton *btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 20) ];
[btnBack setTitle:@"Skip" forState:UIControlStateNormal];
btnBack.titleLabel.font = [UIFont fontWithName:@"SFUIText-Medium" size:15];
[btnBack sizeToFit];
[btnBack addTarget:self action:@selector(backActionEvent:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnSkip];