How to place a UIImage in Navigationbar such that its a logo?

后端 未结 8 734
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 07:30

\"enter\"enterI

相关标签:
8条回答
  • 2020-12-22 08:31

    I had the same problem in my last project, you can create a new logo.png which dimension is equal to 500*88 pixels, make you logo in the left side of it. filled with transparent color from the rest of the png.

    UIImageView *titleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logoName_500.png"]];
    [titleImageView setFrame:CGRectMake(0, 0, 250, 44)];
    self.navigationItem.titleView = titleImageView;
    

    hope this helpful.

    0 讨论(0)
  • 2020-12-22 08:32
    @property(nonatomic,strong) UIView *titleImageView;
    
    
    - (UIView *)titleImageView {
    if (!_titleImageView) {
         CGFloat width = self.view.frame.size.width;
        _titleImageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 44)];
        [self.titleLabelView setBackgroundColor:[UIColor clearColor]];
        UIImage *img = [UIImage imageNamed:@"myImg"];
        UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
        CGRect imageViewRect = imgView.frame;
        /*
        //adjust image position if you need
        imageViewRect.x = 10;
        imageViewRect.y = 3;
        imageView.frame = imageViewRect;
        */
        [_titleLabelView addSubview:imgView];
     }
    return _titleLabelView;
    }
    
    
    self.navigationItem.titleView = self.titleLabelView;
    
    0 讨论(0)
提交回复
热议问题