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

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

\"enter\"enterI

8条回答
  •  我在风中等你
    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;
    

提交回复
热议问题