可能重复:
iPhone 中的自定义字体
我正在尝试创建一个自定义标签以将其设置为titleView
my的一个navigationItem
,但我无法将标签字体设置为我的项目中包含的自定义字体。
我有一个名为“BADER_AL_GORDABIA-2_0.ttf”的自定义字体文件,FontBook 中显示的真实字体名称是“bader_al gordabia-2”我已按照以下步骤操作:
- 检查了我的应用程序的部署目标,它设置为 iOS 5.1
- 将字体文件添加到项目资源中,并在 Build Phases 的“Copy Bundle Resources”中验证是否已添加到构建目标中。
- 在我的 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/