Can I set image as a title to UINavigationBar?

后端 未结 16 1926
有刺的猬
有刺的猬 2020-12-07 09:38

Is it possible to set some image as title of Navigation bar?

I think NYTimes application used a Navigation bar and title is look like image file (the reason why it\'

16条回答
  •  难免孤独
    2020-12-07 10:30

    If your buttons disappear when you navigate back and forth the navigation, this fixed it for me:

    NSArray *mySubviews = navigationBar.subviews;
    UIImageView *iv = nil;
    
    // Move in reverse direction as not to upset the order of elements in the array
    for (int i = [mySubviews count] - 1; i >= 0; i--)
    {
        if ([[mySubviews objectAtIndex:i] isMemberOfClass:[UIImageView class]])
        {
            NSLog(@"found background at index %d",i);
            iv = [mySubviews objectAtIndex:i];
            [[mySubviews objectAtIndex:i] removeFromSuperview];
            [navigationBar insertSubview:iv atIndex:0];
        }
    }
    

提交回复
热议问题