您好,我需要设置右侧的按钮,在导航栏,编程,以便如果我按下按钮,我将执行一些行动。我已经通过编程创建了导航栏;
navBar=[[UINavigationBar alloc]initWithFrame:CGRectMake(0,0,320,44) ];类似地,我需要在这个导航栏的右侧添加按钮。为此我使用了,
1.
UIView* container = [[UIView alloc] init];
// create a button and add it to the container
UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 130, 44.01)];
[container addSubview:button];
[button release];
// add another button
button = [[UIButton alloc] initWithFrame:CGRectMake(160, 0, 50, 44.01)];
[container addSubview:button];
[button release];
// now create a Bar button item
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:container];
// set the nav bar's right button item
self.navigationItem.rightBarButtonItem = item;
[item release];2.
UIImage *im;
im=[UIImage imageNamed:@"back.png"];
[button setImage:im forState:UIControlStateNormal];
[im release];
backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
[backButton setImageInsets:UIEdgeInsetsMake(0, -10,5, 5)];
[self.navigationItem setRightBarButtonItem:backButton];3.
UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithTitle:@"button" style:UIBarButtonItemStylePlain target:self action:@selector(refreshLogsAction:)];
self.navigationItem.rightBarButtonItem = refreshItem;
[refreshItem release];我尝试了所有这些方法,但没有一种方法在右侧显示按钮。
发布于 2015-04-07 23:48:15
如何在swift中将添加按钮添加到导航栏:
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "onAdd:")onAdd:
func onAdd(sender: AnyObject) {
}https://stackoverflow.com/questions/2848055
复制相似问题