【问题标题】:add image and title to the navigationbar of tab based application将图像和标题添加到基于选项卡的应用程序的导航栏
【发布时间】:2011-04-07 08:32:21
【问题描述】:

我想在基于标签的应用程序的导航栏中添加图像和背景图像

【问题讨论】:

    标签: iphone ipad


    【解决方案1】:
     self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navbarimg.png"]];
    

    【讨论】:

    • 在这种情况下我也可以添加标题
    • 您可以添加一个标题,但它只会作为导航按钮的标识(即,如果您在导航控制器中按下另一个视图控制器,后退按钮将具有该标题)。除此之外,这个 titleview 用导航栏上的标题替换了通常包含标签的 UIView,所以如果你想让它在那里播种,你应该在图像中添加带有标题的文本
    • @Ali 您应该在 viewWillAppear 中执行此操作。除此之外,请检查您是否已将图像添加到项目等中。
    【解决方案2】:
    @implementation UINavigationBar (CustomImage)
    - (void)drawRect:(CGRect)rect
    {
      UIImage *image = [UIImage imageNamed: @"your_image_name"];
      [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    }
    @end
    

    设置标题可以试试

    self.title = @"your title";
    

    【讨论】:

    • 它是自动添加到视图中的,我可以使用 self.navigationitem 访问它
    猜你喜欢
    • 2011-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-14
    • 1970-01-01
    相关资源
    最近更新 更多