gpt4 book ai didi

iphone - 如何在按钮之间创建空间?

转载 作者:行者123 更新时间:2023-12-03 19:27:02 25 4
gpt4 key购买 nike

我已经创建了多个按钮,但我不知道如何对齐按钮。

我的代码在这里:

- (void)viewDidLoad 
{
//self.title=@"Asset Management";
[super viewDidLoad];

listOfItems = [[NSMutableArray alloc] init];

[listOfItems addObject:@"User Information"];
[listOfItems addObject:@"Regional Settings"];
[listOfItems addObject:@"Configuration"];

toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 20, 320, 44)];
//UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGs
toolbar.tintColor = [UIColor clearColor];
[toolbar setTranslucent:YES];

// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];

// Create button1
UIBarButtonItem *propertiesButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(button1Pressed)];
[buttons addObject:propertiesButton];
[propertiesButton release];

// Create button2
UIBarButtonItem *commentaryButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(button2Pressed)];
[buttons addObject:commentaryButton];
[commentaryButton release];

// Create button3
UIBarButtonItem *versionsButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(button3Pressed)];
[buttons addObject:versionsButton];
[versionsButton release];

// stick the buttons in the toolbar
[toolbar setItems:buttons animated:NO];
//self.toolbarItems = buttons;
[buttons release];

// and put the toolbar in the nav bar
[[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithCustomView:toolbar] autorelease]];
[toolbar release];

}

如何在按钮之间创建空间。请帮助我。提前致谢!

最佳答案

您可以使用两种内置空格按钮类型之一在工具栏项目之间添加空格UIBarButtonSystemItemFixedSpaceUIBarButtonSystemItemFlexibleSpace

固定间距按钮

UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[fixedSpace setWidth:20];

灵活空间按钮

UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];

在其他工具栏项目之间添加空格键按钮。

关于iphone - 如何在按钮之间创建空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7633066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com