Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使UIBarButton在IPhone中正确对齐_Iphone - Fatal编程技术网

如何使UIBarButton在IPhone中正确对齐

如何使UIBarButton在IPhone中正确对齐,iphone,Iphone,我已经动态添加了工具栏,并且动态添加了按钮,但它显示在左侧,我希望它显示在右侧。 有人能帮我吗我的代码是这样的 CGRect frame = CGRectMake(0, 205, 320, 40); UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:frame]; toolbar.barStyle =UIBarStyleBlackTranslucent; toolbar.tintColor = [UIColor darkGrayCo

我已经动态添加了
工具栏
,并且动态添加了
按钮
,但它显示在左侧,我希望它显示在右侧。 有人能帮我吗我的代码是这样的

 CGRect frame = CGRectMake(0, 205, 320, 40);
 UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:frame];
 toolbar.barStyle =UIBarStyleBlackTranslucent;
 toolbar.tintColor = [UIColor darkGrayColor];


 UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle: @"Done" style:UIBarButtonItemStyleDone target:self action:@selector(foo)];
 NSArray *array = [[NSArray alloc]initWithObjects:backButton,nil];

 [toolbar setItems:array];

我通过简单地添加以下行得到了答案

UIBarButtonItem*BtnSpace=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarbuttonSystemFlexibleSpace目标:自我操作:无]

并将其添加到数组中 现在代码如下所示

 CGRect frame = CGRectMake(0, 205, 320, 40);
 UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:frame];
 toolbar.barStyle =UIBarStyleBlackTranslucent;
 toolbar.tintColor = [UIColor darkGrayColor];


 UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle: @"Done" style:UIBarButtonItemStyleDone target:self action:@selector(foo)];
 NSArray *array = [[NSArray alloc]initWithObjects:backButton,nil];

 [toolbar setItems:array];
self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(0,20,320,480)style:UITableViewStyleGrouped]; CGRect帧=CGRectMake(0,205,320,40); UIToolbar*工具栏=[[UIToolbar alloc]initWithFrame:frame]; toolbar.barStyle=uibarstyleblacktransparent; toolbar.tintColor=[UIColor darkGrayColor]

UIBarButtonItem *BtnSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle: @"Done" style:UIBarButtonItemStyleDone target:self action:@selector(foo)];
NSArray *array = [[NSArray alloc]initWithObjects:BtnSpace,backButton,nil];

[toolbar setItems:array];