ios - iPhone-在 PickerView 中设置字体列表

标签 ios objective-c fonts uipickerview

我必须在 Pickerview 中显示字体列表。当我在选择器 View 委托(delegate)方法中设置字体数组时,名为“Bodoni Ornaments”的字体之一文本在选择器 View 标签中变形,其余所有字体都能正确显示。

请看图片:

enter image description here

我通过这段代码获取字体列表:

#pragma mark- Font Array return methods 

-(NSArray*)fontFamilyArrayReturnMethod
{
    NSLog (@"Font families: %@", [UIFont familyNames]);
    return [UIFont familyNames];
}

选择器 View 委托(delegate)方法代码:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, pickerView.frame.size.width-7, 44)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont fontWithName:[arrayContainFontFamily objectAtIndex:row] size:18];
    label.text = [NSString stringWithFormat:@"%@", [arrayContainFontFamily objectAtIndex:row]];
    return label;    
}

为什么此字体没有作为选择器 View 标签中的文本出现。我需要字体名称文本而不是设计的字符。 任何帮助表示赞赏。

最佳答案

在 Google 上快速搜索“Bodoni Ornaments”后,字体实际上就是这个样子,所以行为实际上是正确的。

--编辑-- 现在,您有以下行:

label.font = [UIFont fontWithName:[arrayContainFontFamily objectAtIndex:row] size:18];

这使得字体名称是使用字体本身编写的。如果您希望“Bodoni Ornaments”显示为文本,则必须删除此行。但是,您将无法再预览每种字体。

关于ios - iPhone-在 PickerView 中设置字体列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22175144/

相关文章:

c# - Windows 应用商店应用程序 - 枚举字体

javascript - 添加自定义字体系列以 react native 文本不起作用

ios - React Native 无法构建示例项目(XCode 8.1/Sierra)

android - 处理 PDF 以减小文件大小/和/或复杂性

ios - 我如何一次只允许屏幕上出现一个 SKSpriteNode 实例?

java - 在循环中使用字体大小

iphone - 解析一个 NSURL mailto

iphone - iOS - 当 AFHTTPClient 完成所有操作时如何获得通知

ios - 使用 NSTimer 切换图像

objective-c - 高效访问众多 Cocoa 控件