带UILabels的UIToolbar灵活的空间无法正常工作

时间:2012-06-12 18:21:39

标签: iphone xcode uilabel uitoolbar

我正在创建一个工具栏,上面会有2个标签。

在左边我想要我的税号。 在右边,我想要我的总标签。

这是我在viewDidLoad方法中设置的代码。

self.taxLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0 , 11.0f, self.view.frame.size.width, 21.0f)];
self.taxLabel.backgroundColor = [UIColor clearColor];
self.taxLabel.textColor = [UIColor whiteColor];
self.taxLabel.text = @"$$$$.$$ TAX"; 


self.totalLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0 , 11.0f, self.view.frame.size.width, 21.0f)];
self.totalLabel.backgroundColor = [UIColor clearColor];
self.totalLabel.textColor = [UIColor greenColor];
[self.totalLabel setTextAlignment:UITextAlignmentRight];
self.totalLabel.text = @"$$$$.$$"; 

// create the bar button item where we specify the label as a view to use to init with
UIBarButtonItem *taxButton = [[UIBarButtonItem alloc] initWithCustomView:self.taxLabel];

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

UIBarButtonItem *totalButton = [[UIBarButtonItem alloc] initWithCustomView:self.totalLabel];

NSArray *toolbarItemArr = [NSArray arrayWithObjects:taxButton, flex, totalButton, nil];

[infoBar setItems:toolbarItemArr animated:YES];

我遇到的问题是灵活空间似乎没有做任何事情。 如果我将总标签文本设置为左对齐,则它会与税标签重叠。这几乎就好像它们被添加到工具栏中一样。

标签也可以相互重叠。我不确定我做错了什么。但我认为这与我如何启动框架有关。

任何帮助都将不胜感激。

0 个答案:

没有答案
相关问题