如何在UITabbar上放置UILabel?

时间:2013-01-21 12:51:39

标签: ios uitabbarcontroller uitabbar

我希望在UITabbar上放置UILabel,我该如何实现呢?

1 个答案:

答案 0 :(得分:0)

假设您使用带有工具栏的UINavigationController,这应该可以解决问题: (它的两侧都有一个灵活的空间来居中。

CGRect myFrame = CGRectMake(0, 0, 100, 44);
UILabel *myLabel = [[UILabel alloc] initWithFrame:myFrame];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];
UIBarButtonItem *labelItem = [[UIBarButtonItem alloc] initWithCustomView:myLabel];
UIBarButtonItem *spaceItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];
[self setToolbarItems:[NSArray arrayWithObjects:spaceItem,labelItem,spaceItem2, nil] animated:YES];