OGeek|极客世界-中国程序员成长平台

标题: iphone - 左箭头 - UINavigationItem [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 06:14
标题: iphone - 左箭头 - UINavigationItem

我已经四处寻找,但似乎无法弄清楚。我相信很多人都会为我提供链接等,我很可能已经看过了。但如果有人可以请给我看代码来执行以下操作:

我想在我的 UINavigationBar 中有一个左箭头作为“返回”UINavigationItem。我怎样才能做到这一点?这是我的 UIViewController 中的当前代码:

theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];

UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle"Back" style:UIBarButtonItemStyleBordered target:nil actionselector(backButtonSelected];

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle"Options" style:UIBarButtonItemStyleBordered target:nil actionselector(optionsButtonSelected];

UINavigationItem *item = [[UINavigationItem alloc] initWithTitle"Title"];
item.leftBarButtonItem = leftButton;
item.hidesBackButton = YES;
item.rightBarButtonItem = rightButton;

[self.view addSubview:theBar];



Best Answer-推荐答案


我想这可能就是你要找的。

// in .h file
@property (nonatomic, retain) UINavigationBar *navBar;

// in .m file just below @implementation
@synthesize navBar;


// within .m method
navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
navBar.barStyle = UIBarStyleBlack;

UINavigationItem *title = [[UINavigationItem alloc] initWithTitle"Nav Bar Title"];

UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] 
                       initWithTitle"Back" 
                               style:UIBarButtonItemStylePlain 
                              target:nil
                              actionselector(backButtonSelected];

title.leftBarButtonItem = leftButton; 

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] 
         initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                              target:nil
                              actionselector(showActionSheet];

title.rightBarButtonItem = rightButton;

[navBar pushNavigationItem:title animated:YES];

[self.view addSubview:navBar];

关于iphone - 左箭头 - UINavigationItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4596234/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4