UINavigationBar navigationItem标题高度

时间:2016-08-25 07:42:30

标签: objective-c uinavigationbar uinavigationitem

我使用包含变音符号的导航项目标题文本的自定义字体和大写文本。问题是,变音符号是从顶部剪切的,可能是因为标题标签的高度错误。

所以问题是,我可以影响标题标签的高度吗?或直接访问标题标签并执行sizeToFit或更改框架等内容。

// custom font settings
NSDictionary *attr = @{
                       NSFontAttributeName:  [UIFont fontWithName:@"FishmongerK-XCondLight" size:23.0],
                       NSForegroundColorAttributeName: [UIColor whiteColor]
                       };

[[UINavigationBar appearance] setTitleTextAttributes: attr];

// then setting of title
self.navigationItem.title = [NSLocalizedString(@"Oblíbené", nil) uppercaseString];

如果我尝试更小的字体大小,变音符号仍会从顶部剪切。

1 个答案:

答案 0 :(得分:0)

-(void)setCustomNavTitle:(NSString*)title andDescription:(NSString*)desc {

NSString * locname = [NSString stringWithFormat:@"%@\n", title];
NSString * cityname = [NSString stringWithFormat:@"%@", desc];
NSString * text = [NSString stringWithFormat:@"%@%@", [locname capitalizedString], cityname];

NSDictionary *attribs = @{
                          NSForegroundColorAttributeName:[UIColor colorWithHexString:@"222222"],
                          NSFontAttributeName: [UIFont fontWithName:[[Variables getInstance] HelveticaNeue] size:14]
                          };
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text attributes:attribs];

NSRange range = [text rangeOfString:cityname];
[attributedText setAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"222222"],
                                NSFontAttributeName:[UIFont fontWithName:[[Variables getInstance] HelveticaNeueLight] size:14]} range:range];

UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 44)];
titleLabel.font = [UIFont fontWithName:[[Variables getInstance] HelveticaNeueMedium] size:15];
titleLabel.attributedText = attributedText;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.numberOfLines=0;
titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
titleLabel.textColor = [UIColor blackColor];
self.navigationItem.titleView = titleLabel;

}

相关问题