如何创建类似于iOS中WhatsApp的多线导航栏?

时间:2012-07-08 17:30:48

标签: ios uinavigationbar

有没有人知道如何在iOS中创建多行导航/顶栏?我想要类似于WhatsApp中的状态行(显示上次显示的状态行或当前状态信息)。 任何建议将不胜感激。

我希望在图像中实现类似的东西(Francis Whitman /上次见过[...]):

enter image description here

2 个答案:

答案 0 :(得分:3)

默认情况下,UINavigationController将使用当前显示的视图控制器的title属性作为其导航栏中的标题。但是,您可以通过设置视图控制器的titleView属性的navigationItem属性来显示任意视图,如下所示:

// In your view controller’s implementation (.m) file:
- (id)initWithNibName:(NSString *)nibName
               bundle:(NSStirng *)nibBundle
{
    self = [super initWithNibName:nibName bundle:nibBundle];

    if (self) {
        UIView *myTitleView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,
                                                                       0.0f,
                                                                       250.0f,
                                                                       44.0f)];
        [myView setBackgroundColor:[UIColor greenColor]];

        [[self navigationItem] setTitleView:myTitleView];
    }

    return self;
}

答案 1 :(得分:0)

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width/2, 200)];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setTextAlignment:NSTextAlignmentCenter];
[label setNumberOfLines:0];
[label setText:_certificate.name];
self.navigationItem.titleView = label;