How to change back bar button's width of a UINavigationController in iPhone?

可紊 提交于 2019-12-24 07:17:21

问题


I have two table view controllers. Say TableViewController1 and TableViewController2.

I push TableViewController2 when someone clicks on the TableViewController1's cell.

I set the TableViewController1's clicked cell's value as the TableViewController2's back bar button's title value.

According to the length of the TableViewController1 cell's string, the back bar button's length also get changing.

Is it possible to fix the width of the back bar button? I really need this, because I want to capture the tap events of the TableViewController2 navigation bar's titleView.

Back bar button's width affects the titleView's width. So I can not find the bounds of the titleView. Or is there any other way to find the bounds value of a titleView of Navigation bar?


回答1:


Is it possible to fix the width of the back bar button?

As far as I know you can not edit this button.

Subclassing it would be the way to go, or you might want to truncate the title from the previous viewController. Alternatively you might want to replace with with a normal UIBarButtonItem like so:

- (void) viewDidLoad
{
    [super viewDidLoad];
    self.title = @”shortTitle.”;

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                            style:UIBarButtonItemStyleBordered
                            target:nil
                            action:nil];

    self.navigationItem.backBarButtonItem = backButton;
    [backButton release];
 }


来源:https://stackoverflow.com/questions/7824220/how-to-change-back-bar-buttons-width-of-a-uinavigationcontroller-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!