Add title and image to navigation bar

I need to set the UIViewController name and image in the navigationBar. While I can display the image, but the name, of course, is missing.

// show image UIImage *image = [UIImage imageNamed: @"bar_icon.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage: image]; imageView.frame = CGRectMake(0, 0, 40, 40); self.navigationItem.titleView = imageView; [imageView release]; 

Thank you for your help,
BR, doonot

+4
source share
2 answers
  // show image UIImage *image = [UIImage imageNamed: @"bar_icon.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage: image]; imageView.frame = CGRectMake(70, 0, 40, 40); // label UILabel *tmpTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 100, 40)]; tmpTitleLabel.text = @"Mannschaft"; tmpTitleLabel.backgroundColor = [UIColor clearColor]; tmpTitleLabel.textColor = [UIColor whiteColor]; CGRect applicationFrame = CGRectMake(0, 0, 300, 40); UIView * newView = [[[UIView alloc] initWithFrame:applicationFrame] autorelease]; [newView addSubview:imageView]; [newView addSubview:tmpTitleLabel]; self.navigationItem.titleView = newView; [imageView release]; [tmpTitleLabel release]; 
+8
source

Create a UIView with 2 subviews: UIImageView and UILabel. Set titleView to UIView.

+4
source

Source: https://habr.com/ru/post/1345331/


All Articles