问题
In my application I have to add 8 buttons on a navigation bar..So it's very much normal that these button should be in a view and there should be one previous and next button. When i will press the next button then using animation it will show the next buttons whose are out of the view and same as for previous button.
For Details:
UINavigation Bar -> leftBaritem[previous button] + view + rightBaritem[next button];
view will contain 8 buttons. If I explain again then it should be look like this:
Previous + | A | B | C | D | E | F | G | H + next
when I will press
next
then it will show like this:
previous + | B | C | D | E | F | G | H + next
like this for
previous
button.
EDIT:
In this picture there are three button in a view but i have six button to add on the view "Dashbord , order , Product". Now when i will press ">" or "<" or left/right bar items then it will show the buttons of the nav bar which are out of the view.
回答1:
You're doing the wrong thing. You should not be trying to force 8 buttons into a navigation bar.
You need to rethink your interface. Two reasonable approaches come to mind:
Use a tab bar. A tab bar has support for handling more options than will fit on the screen. For example, the built-in Music app has 10 tabs.
Put your eight buttons in a full-screen view under a navigation controller. When the user clicks one, push the appropriate view for that button. The user can pop back (using the navigation controller's normal back button support) to pick a different button.
回答2:
I have solve this problem slightly different way....
In viewDidLoad I have take a scrollView and called my function
menuScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,40)];
menuScrollView.showsHorizontalScrollIndicator = FALSE;
menuScrollView.showsVerticalScrollIndicator = FALSE;
menuScrollView.bounces = TRUE;
[self createMenuWithButtonSize:CGSizeMake(70.0, 30.0) withOffset:20.0f noOfButtons:7];
Then in my function i have created my menu buttons which will be look like buttons on a navigation bar
-(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons{
NSLog(@"inserting into the function for menu bar button creation");
for (int i = 0; i < totalNoOfButtons; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(mybuttons:) forControlEvents:UIControlEventTouchUpInside];
if(i==0){
[button setTitle:[NSString stringWithFormat:@"Dashboard"] forState:UIControlStateNormal];//with title
}
else if(i==1){
[button setTitle:[NSString stringWithFormat:@"Order"] forState:UIControlStateNormal];//with title
}
else if(i==2){
[button setTitle:[NSString stringWithFormat:@"Product"] forState:UIControlStateNormal];//with title
}
else if(i==3){
[button setTitle:[NSString stringWithFormat:@"Customers"] forState:UIControlStateNormal];//with title
}
else if(i==4){
[button setTitle:[NSString stringWithFormat:@"Content"] forState:UIControlStateNormal];//with title
}
else if(i==5){
[button setTitle:[NSString stringWithFormat:@"Site Analysis"] forState:UIControlStateNormal];//with title
}
else if(i==6){
[button setTitle:[NSString stringWithFormat:@"Store Settings"] forState:UIControlStateNormal];//with title
}
else if(i==7){
[button setTitle:[NSString stringWithFormat:@"CMS Settings"] forState:UIControlStateNormal];//with title
}
button.frame = CGRectMake(i*(offset+buttonSize.width), 8.0, buttonSize.width, buttonSize.height);
button.clipsToBounds = YES;
button.showsTouchWhenHighlighted=YES;
button.layer.cornerRadius = 0;//half of the width
//button.layer.borderColor=[UIColor clearColor];
button.layer.backgroundColor=[UIColor blueColor].CGColor;
button.titleLabel.font = [UIFont systemFontOfSize:10];
button.layer.borderWidth=0.0f;
button.tag=i;
[menuScrollView addSubview:button];
}
menuScrollView.contentSize=CGSizeMake((buttonSize.width + offset) * totalNoOfButtons, buttonSize.height);
[self.view addSubview:menuScrollView];
}
and it solves...Happy Coding... :))
来源:https://stackoverflow.com/questions/8284077/how-can-i-add-more-than-10-buttons-on-a-navigationbar-in-iphone-application-deve