Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change label text of custom UINavigationBar class
    text
    copied!<p>I am trying to create a custom navigation bar class. Here is my code. The question is how can I set the label text (<code>navTitle</code> and <code>teamName</code>) with my own method from other class. Like this method <code>[self.navigationbar setTitle:@""]</code>. </p> <pre><code>#import "CustomNavigationBar.h" @implementation CustomNavigationBar - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } - (void)drawRect:(CGRect)rect { // Drawing code [self setBackgroundColor:[UIColor clearColor]]; CGContextRef context = UIGraphicsGetCurrentContext(); UIImage *navImage = [UIImage imageNamed:@"nav"]; CGRect r = CGRectMake(0, 0, 320, 44); CGContextDrawTiledImage(context, r, navImage.CGImage); UIImageView *teamId = [[UIImageView alloc] initWithFrame: CGRectMake(210, 17, 40, 10)]; teamId.image = [UIImage imageNamed:@"team"]; UILabel *navTitle = [[UILabel alloc] initWithFrame: CGRectMake(10, 2, 200, 39)]; navTitle.autoresizingMask = UIViewAutoresizingFlexibleWidth; navTitle.text = @"title"; navTitle.backgroundColor = [UIColor clearColor]; navTitle.textColor = [UIColor blackColor]; navTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:15]; UILabel *teamName = [[UILabel alloc] initWithFrame: CGRectMake(255, 18, 78, 10)]; teamName.autoresizingMask = UIViewAutoresizingFlexibleWidth; teamName.backgroundColor = [UIColor clearColor]; teamName.textColor = [UIColor blackColor]; teamName.font = [UIFont fontWithName:@"Helvetica-Bold" size:10]; [self addSubview:teamId]; [self addSubview:navTitle]; [self addSubview:teamName]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload