【发布时间】:2013-01-14 18:50:33
【问题描述】:
我正在尝试创建一个自定义标签以将其设置为我的navigationItem 的titleView,但我无法将标签字体设置为我的项目中包含的自定义字体。
我有一个名为“BADER_AL_GORDABIA-2_0.ttf”的自定义字体文件,FontBook 中显示的真实字体名称是“bader_al gordabia-2” 我已按照以下步骤操作:
- 检查了我的应用的部署目标,设置为 iOS 5.1
- 将字体文件添加到项目资源中,并在构建阶段的“复制捆绑资源”中验证已添加到构建目标。
- 在我的 info.plist 文件中添加了一个新键作为“应用程序提供的字体”,并在其中添加了“BADER_AL_GORDABIA-2_0.ttf”。
- 在 fontWithName 方法中使用了真正的字体名称“bader_al gordabia-2”。
我能够使用
加载字体UIFont * customFont = [UIFont fontWithName:@"bader_al gordabia-2" size:18.0f];
我确保 customFont 不为空(通过打印其描述),但问题是我无法将此自定义字体应用于 UILabel。
我的代码是:
UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(100,10,200,24)];
titleLabel.backgroundColor = [UIColor clearColor];
UIFont * customFont = [UIFont fontWithName:@"bader_al gordabia-2" size:18.0f];
[titleLabel setFont:customFont];
titleLabel.text = @"أخبار الجمعية";
//NSLog(@"%@", [customFont description]);
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = [UIColor whiteColor];
[self.navigationItem setTitleView:titleLabel];
我尝试搜索堆栈溢出,但找不到合适的答案。 我还尝试使用以下链接中指定的自定义标签: http://refactr.com/blog/2012/09/ios-tips-custom-fonts/
【问题讨论】:
标签: iphone objective-c uilabel uinavigationitem uifont