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
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;
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With