我有4 UIBarButtonItem(penButton,textButton,highlightButton & stampButton)裏面1 UIToolBar,我試圖讓每個按鈕垂直排隊,現在他們排隊水平。UIToolbar內UIBarButtonItem位置
NSBundle *currentBundle = [NSBundle bundleForClass:[self class]];
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(5, 20, 200, 200)];
[toolBar setBackgroundColor:[UIColor clearColor]];
UIButton *penTool = [UIButton buttonWithType:UIButtonTypeCustom];
penTool.frame = CGRectMake(0, 0, 30, 30);
[penTool setImage:[UIImage imageNamed:@"pen-but" inBundle:currentBundle compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
[penTool addTarget:self action:@selector(drawButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
penTool.autoresizingMask = UIViewAutoresizingNone;
penTool.exclusiveTouch = YES;
penTool.tag = 1;
UIBarButtonItem * penButton = [[[UIBarButtonItem alloc] initWithCustomView:penTool] autorelease];
UIButton *textTool = [UIButton buttonWithType:UIButtonTypeCustom];
textTool.frame = CGRectMake(0, 0, 30, 30);
[textTool setImage:[UIImage imageNamed:@"text-but" inBundle:currentBundle compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
[textTool addTarget:self action:@selector(drawButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
textTool.autoresizingMask = UIViewAutoresizingNone;
textTool.exclusiveTouch = YES;
textTool.tag = 2;
UIBarButtonItem * textButton = [[[UIBarButtonItem alloc] initWithCustomView:textTool] autorelease];
UIButton *highlightTool = [UIButton buttonWithType:UIButtonTypeCustom];
highlightTool.frame = CGRectMake(0, 0, 30, 30);
[highlightTool setImage:[UIImage imageNamed:@"squarefill-but" inBundle:currentBundle compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
[highlightTool addTarget:self action:@selector(drawButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
highlightTool.autoresizingMask = UIViewAutoresizingNone;
highlightTool.exclusiveTouch = YES;
highlightTool.tag = 3;
UIBarButtonItem * highlightButton = [[[UIBarButtonItem alloc] initWithCustomView:highlightTool] autorelease];
UIButton *stampTool = [UIButton buttonWithType:UIButtonTypeCustom];
stampTool.frame = CGRectMake(8, 8, 30, 30);
[stampTool setImage:[UIImage imageNamed:@"approved" inBundle:currentBundle compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
[stampTool addTarget:self action:@selector(drawButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
stampTool.autoresizingMask = UIViewAutoresizingNone;
stampTool.exclusiveTouch = YES;
stampTool.tag = 4;
UIBarButtonItem * stampButton = [[[UIBarButtonItem alloc] initWithCustomView:stampTool] autorelease];
NSArray *buttons = [NSArray arrayWithObjects: penButton, textButton, highlightButton, stampButton, nil];
[toolBar setItems:buttons animated:NO];
[self.view addSubview:toolBar];
我該如何解決這個問題,讓他們垂直排隊?
所以你試着做一個垂直工具欄? – CZ54