Reputation: 207
For the moment I just know how to put a string as a title with:
[self setTitle:@"iOS CONTROL"];
or an image with
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
but not both in the same time
there is a solution ? Thank you
Upvotes: 8
Views: 3443
Reputation: 2365
You can create a UIView
and add as many subviews as you like. For example:
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 40.0)];
titleView.backgroundColor = [UIColor clearColor];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textColor = [UIColor redColor];
titleLabel.text = @"My Title Label";
[titleLabel sizeToFit];
...
// Set the frames for imageView and titleLabel to whatever you need them to be
...
[titleView addSubview:imageView];
[titleView addSubview:titleLabel];
self.navigationItem.titleView = titleView;
Upvotes: 16
Reputation: 19303
Create a new UIView
, add UIImage
and a UILabel
as subviews to it the way you want and add that UIView
using self.navigationItem.titleView
.
Upvotes: 1