0

我已将 UINavigationBar titleView 设置如下:

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];

现在我想更新 UINavigationBar 的高度,因为在我们增加 UINavigationBar 的高度之前,标题视图中的自动换行不会显示。我该怎么做?

4

3 回答 3

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...

于 2012-04-16T10:30:07.307 回答
0

我认为您必须使用自定义图像创建一个自定义 UINavigationBar,然后您可以做任何您想做的事情。

于 2012-04-16T10:28:21.247 回答
-1

尝试这个,

@implementation UINavigationBar (CustomHeight)

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

@end
于 2012-04-16T10:29:15.040 回答