Using UIAppearance to change label height

前端 未结 2 1624
南旧
南旧 2021-01-15 04:05

Is there any way to use UIAppearance to change the height of a label inside of a UINavigationBar. Here\'s the code and an image of what\'s going on so you can understand wh

相关标签:
2条回答
  • 2021-01-15 04:46

    Probably you can get the UIAppearance for UILabel inside UINavigationBar.

    0 讨论(0)
  • 2021-01-15 04:54

    I ended up solving this by creating a custom UIView:

    +(NavigationBarTitleLabel *)titleLabelWithTitle:(NSString *)title {
      // this will appear as the title in the navigation bar
      NavigationBarTitleLabel *labelWrapper = [[NavigationBarTitleLabel alloc] initWithFrame:CGRectMake(0, 0, 200, 34)];
      UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 8, 200, 32)];
    
      label.font            = [UIFont fontWithName:@"MarketingScript" size:28.0];
      label.text            = title;
      label.textColor       = XHEXCOLOR(0XFFFFFF);
      label.textAlignment   = UITextAlignmentCenter;
      label.backgroundColor = [UIColor clearColor];
      label.layer.shadowColor = [UIColor blackColor].CGColor;
      label.layer.shadowRadius = 2;
      [labelWrapper addSubview:label];
      [labelWrapper sizeToFit];
    
      return labelWrapper;
    }
    

    and then setting the titleView property on the navigationItem:

    self.navigationItem.titleView = [NavigationBarTitleLabel titleLabelWithTitle:self.title];
    
    0 讨论(0)
提交回复
热议问题