0

I have set UINavigationBar titleView as given below:

UIView *labelView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 255, 40)];
       UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 40)];
       [label setTextColor:[UIColor whiteColor]];
        label.lineBreakMode=UILineBreakModeWordWrap;
        label.numberOfLines=0;
        label.shadowColor = [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.25f];
        label.shadowOffset = CGSizeMake(0.0f, -1.0f);
        label.textAlignment = UITextAlignmentCenter;
        label.adjustsFontSizeToFitWidth=YES;


      [label setBackgroundColor:[UIColor clearColor]];

      switch (genreId) {
       case 1:
        label.text=@"Music";
        self.navigationItem.titleView =label;
        break;
       case 3:
        label.text=@"Family";
        break;
       case 6:
        label.text=@"Literature";
        break;
       case 7:
        label.text=@"Theatre";
        break;
       default:
        label.frame=CGRectMake(0, 0, 255, 40);
        label.text=ArtistName;
        break;
      }


      [label setFont:[UIFont boldSystemFontOfSize:20.0]];
      [labelView  addSubview:label];
      [self.navigationItem setTitleView:labelView];

      [label release];

Now I want to update the height of UINavigationBar because word wrap in title view will not display until we increase the height of the UINavigationBar.How can I do that?

Prince Kumar Sharma
  • 12,591
  • 4
  • 59
  • 90

3 Answers3

3

use this code.....and chill......

NSString *summary;
summary = @" your title";

 // define font size what ever you want....
CGSize s = [summary sizeWithFont:[UIFont systemFontOfSize:30] 
               constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT)     // - 40 For cell padding
                   lineBreakMode:UILineBreakModeWordWrap];



CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, s.height);
[self.navigationController.navigationBar setFrame:frame];

Hope, it will help you...

Nitin
  • 7,455
  • 2
  • 32
  • 51
  • Thanks for the solution. It is working perfectly but there is a problem increasing height of navigation bar hides the views below it like table view or search bar etc. – Prince Kumar Sharma Apr 18 '12 at 11:22
0

I think you have to create a Custom UINavigationBar with custom image then you can do whatever you want.

user1226038
  • 77
  • 1
  • 9
-1

try this,

@implementation UINavigationBar (CustomHeight)

- (void)layoutSubviews {
  [super layoutSubviews];
  CGRect barFrame = self.frame;
  barFrame.size.height = height;
  self.frame = barFrame;
}

@end
Krunal
  • 6,440
  • 21
  • 91
  • 155
  • 2
    You shouldn't use categories to override methods you don't own – Paul.s Apr 16 '12 at 11:18
  • Will you get banned from the App store if you override such methods ( methods that you don't own) ? Thanks in advance. – nluo Dec 18 '12 at 06:01