我的问题是,在MasterDetail模板中将我自己的按钮放在主视图的上方栏上最合适的方法是什么。
我想将自己的按钮放在MasterDetail模板中Master视图的Top部分。它到达时左侧有一个编辑按钮,右侧有一个添加(+)按钮。我注释掉了.m文件中的“编辑”按钮。我在自己的按钮上吸毒。我注意到的第一件事是我的按钮看起来与右边的+按钮不同。它似乎是统一的大小。接下来的事情是,当我创建我的按钮时,它没有指定事件的地方(内部触摸)。我可以以某种方式修改self.editButtonItem。当然这是常见的事情 - 更换我们的按钮。 thaks
答案 0 :(得分:2)
创建两个自定义按钮并在导航项目上设置..
// Set navigation left button
UIButton *btnLeft = [UIButton buttonWithType:UIButtonTypeCustom];
[btnLeft setBackgroundImage:[UIImage imageNamed:@"button_signup.png"] forState:UIControlStateNormal];
[btnLeft addTarget:self action:@selector(skipImage:) forControlEvents:UIControlEventTouchUpInside];
[btnLeft setFrame:CGRectMake(0, 0, 60, 29)];
[btnLeft setTitle:@"Skip" forState:UIControlStateNormal];
[btnLeft setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btnLeft .titleLabel setFont:[UIFont fontWithName:@"Futura" size:15.0]];
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];
[self.navigationItem setLeftBarButtonItem:leftBarButton];
//
// Set navigation right button
btnRight = [UIButton buttonWithType:UIButtonTypeCustom];
[btnRight setBackgroundImage:[UIImage imageNamed:@"button_signup.png"] forState:UIControlStateNormal];
[btnRight addTarget:self action:@selector(nextImage:) forControlEvents:UIControlEventTouchUpInside];
[btnRight setFrame:CGRectMake(0, 0, 60, 29)];
[btnRight setTitle:@"Next" forState:UIControlStateNormal];
[btnRight setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btnRight.titleLabel setFont:[UIFont fontWithName:@"Futura" size:15.0]];
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:btnRight];
[self.navigationItem setRightBarButtonItem:rightBarButton];
//
答案 1 :(得分:1)
此示例应解决您的问题:http://rogchap.com/2011/06/21/custom-navigation-bar-background-and-custom-buttons/ ..最初在这里回答 - > Custom Navigation Bar Buttons ..