我必须在 Pickerview 中显示字体列表。当我在选择器 View 委托(delegate)方法中设置字体数组时,名为“Bodoni Ornaments”的字体之一文本在选择器 View 标签中变形,其余所有字体都能正确显示。
请看图片:
我通过这段代码获取字体列表:
#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/