自定义导航栏的字体和颜色,只需要自定义一个lable,然后将lable添加到导航栏的titleview中就可以了
代码如下
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];//这个frame是初设的,没关系,后面还会重新设置其size。 [label setNumberOfLines:0]; UIFont *font = [UIFont fontWithName:@"Arial" size:17]; label.font = font; label.text = @"二维码结果"; CGSize size = CGSizeMake(320,2000); //设置一个行高上限 NSDictionary *attribute = @{NSFontAttributeName: label.font}; CGSize labelsize = [label.text boundingRectWithSize:size options: NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:attribute context:nil].size; //动态根据文本内容设置lable的大小 [label setFrame:CGRectMake(0,0, labelsize.width, labelsize.height)]; self.navigationItem.titleView = label;
假如想获取ios系统本身所自带的全部字体,并且在调试模式下输出,可使用以下代码
NSArray* fontFamilys = [UIFont familyNames]; for (int i = 0; i<[fontFamilys count]; i++) { NSString* family = [fontFamilys objectAtIndex:i]; NSLog(@"系统自带字体有:%@rn=====",family); NSArray* fonts = [UIFont fontNamesForFamilyName:family]; for (int j = 0; j<[fonts count]; j++) { NSLog(@"%@",[fonts objectAtIndex:j]); } }
时间: 2024-10-10 06:46:14