如何使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];