我已经看到许多应用程序在 uinavigationbar 上有一个信息按钮(字母“i”,周围有一个圆圈)。如何添加这种类型的按钮?
问问题
7809 次
4 回答
31
以前的答案很接近,没有完全编译。这是你真正想要的:
// Info button
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(showInfoView:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
于 2009-09-22T17:05:46.113 回答
3
上面的答案存在内存泄漏。您应该使用“自动释放”来避免它。我试图编辑答案,但到目前为止我还没有成功。
// Info button
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(showInfoView:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:infoButton] autorelease];
这是正确的方法。
于 2011-12-03T10:40:01.797 回答
0
您应该能够向 UINavigationController 当前显示的视图控制器的 navigationItem 添加“信息灯”类型的按钮。像这样的东西可能会出现在您的视图控制器代码中:
- (void) viewDidLoad {
UIButton * info = [UIButton buttonWithType:UIButtonTypeInfoLight];
// set your button's target and selector for whatever action here.
self.navigationItem.rightBarButtonItem.customView = info;
}
于 2009-09-21T18:58:48.180 回答
0
您还可以将当前条形按钮项目的目标和选择器用于您的信息按钮。
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self.barButtonItem.target action:self.barButtonItem.action forControlEvents:UIControlEventTouchUpInside];
self.barButtonItem.customView = infoButton;
This way, any actions or segues coupled to your bar button item will be transferred to your info button.
于 2014-12-09T15:18:05.933 回答