这是我目前使用的代码。不幸的是,UISegmentControl不是该条的最大宽度。有没有一种快速简便的方法可以将代码的最大宽度设置为不需要精确的帧宽来设置?如何将UINavigationBar中的UISegmentControl的宽度动态设置为最大宽度?
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(addItem:)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
UISegmentedControl *segBar = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"First", @"Second", @"Third", nil]] autorelease];
[segBar setSegmentedControlStyle:UISegmentedControlStyleBar];
[segBar sizeToFit];
self.navigationItem.titleView = segBar;
下面是它目前的样子:
这是我希望它看起来像:
谢谢,这符合我的需求。我没有使用ARC,因为我正在修改其他人的旧项目。我稍后会解决这个问题。 – 2014-09-03 18:14:07
非常好,很高兴帮助!祝你好运! – Mike 2014-09-03 18:14:37