問題描述
在我的應用程序中,我必須在導航欄上添加 8 個按鈕.所以這些按鈕應該在視圖中并且應該有一個上一個和下一個按鈕是非常正常的.當我按下下一個按鈕然后使用動畫時,它將顯示下一個按鈕,這些按鈕不在視圖中并且與上一個按鈕相同.
詳情:
UINavigation Bar -> leftBaritem[上一個按鈕] + view + rightBaritem[下一個按鈕];
視圖將包含 8 個按鈕.如果我再解釋一下,它應該是這樣的:
<塊引用>
上一個 + |一個 |乙|C |D |E |F |克|H + 下一個
我什么時候按
<塊引用>下一個
然后它會顯示如下:
<塊引用>上一個 + |乙|C |D |E |F |克|H + 下一個
喜歡這個
<塊引用>上一頁
按鈕.
在這張圖片中,一個視圖中有三個按鈕,但我有六個按鈕可以添加到儀表板、訂單、產品"視圖上.現在當我按下>"或<"時或左/右欄項目,然后它將顯示導航欄的按鈕,這些按鈕不在視圖中.
我解決這個問題的方式略有不同......
在 viewDidLoad
我有一個 scrollView
并調用了我的函數
menuScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,40)];menuScrollView.showsHorizo??ntalScrollIndicator = FALSE;menuScrollView.showsVerticalScrollIndicator = FALSE;menuScrollView.bounces = TRUE;[self createMenuWithButtonSize:CGSizeMake(70.0, 30.0) withOffset:20.0f noOfButtons:7];
然后在我的 function
中,我創建了我的菜單 buttons
,它看起來像 navigation bar
-(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons{NSLog(@"插入菜單欄按鈕創建函數");for (int i = 0; i < totalNoOfButtons; i++) {UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];[按鈕 addTarget:self action:@selector(mybuttons:) forControlEvents:UIControlEventTouchUpInside];如果(我==0){[button setTitle:[NSString stringWithFormat:@"Dashboard"] forState:UIControlStateNormal];//帶標題}否則如果(i==1){[button setTitle:[NSString stringWithFormat:@"Order"] forState:UIControlStateNormal];//帶標題}否則如果(i==2){[button setTitle:[NSString stringWithFormat:@"Product"] forState:UIControlStateNormal];//帶標題}否則如果(i==3){[button setTitle:[NSString stringWithFormat:@"Customers"] forState:UIControlStateNormal];//帶標題}否則如果(i==4){[button setTitle:[NSString stringWithFormat:@"Content"] forState:UIControlStateNormal];//帶標題}否則如果(i==5){[button setTitle:[NSString stringWithFormat:@"Site Analysis"] forState:UIControlStateNormal];//帶標題}否則如果(i==6){[button setTitle:[NSString stringWithFormat:@"Store Settings"] forState:UIControlStateNormal];//帶標題}否則如果(i==7){[button setTitle:[NSString stringWithFormat:@"CMS Settings"] forState:UIControlStateNormal];//帶標題}button.frame = CGRectMake(i*(offset+buttonSize.width), 8.0, buttonSize.width, buttonSize.height);button.clipsToBounds = YES;button.showsTouchWhenHighlighted=YES;button.layer.cornerRadius = 0;//寬度的一半//button.layer.borderColor=[UIColor clearColor];button.layer.backgroundColor=[UIColor blueColor].CGColor;button.titleLabel.font = [UIFont systemFontOfSize:10];button.layer.borderWidth=0.0f;按鈕.標簽=我;[menuScrollView addSubview:button];}menuScrollView.contentSize=CGSizeMake((buttonSize.width + offset) * totalNoOfButtons, buttonSize.height);[self.view addSubview:menuScrollView];}
它解決了...快樂編碼... :))
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.
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... :))
這篇關于如何在 iphone 應用程序開發中的導航欄上添加 10 多個按鈕?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!