0
即使相应的代码在Swift中工作,我也无法在Objective C中显示分数。我必须失去一些非常明显的东西?在目标C中创建包含分数的字体描述符
Swift代码:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
//: Playground - noun: a place where people can play
let pointSize = self.label.font.pointSize
let systemFontDesc = UIFont.systemFont(ofSize: pointSize, weight: UIFontWeightLight).fontDescriptor
let fractionFontDesc = systemFontDesc.addingAttributes(
[
UIFontDescriptorFeatureSettingsAttribute: [
[
UIFontFeatureTypeIdentifierKey: kFractionsType,
UIFontFeatureSelectorIdentifierKey: kDiagonalFractionsSelector,
], ]
])
print(fractionFontDesc)
self.label.font = UIFont(descriptor: fractionFontDesc, size:pointSize)
print("label.font.descriptor: \(self.label.font.fontDescriptor)")
}
结果:
在目标C等效代码
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
CGFloat pointSize = _label.font.pointSize;
UIFontDescriptor *systemFontDesc = [UIFont systemFontOfSize:pointSize weight:UIFontWeightLight].fontDescriptor;
UIFontDescriptor *fractionDescriptor = [systemFontDesc fontDescriptorByAddingAttributes:@{ UIFontDescriptorFeatureSettingsAttribute : @{
UIFontFeatureTypeIdentifierKey: @(11), // kFractionsType
UIFontFeatureSelectorIdentifierKey: @(2)}}]; // kDiagonalFractionsSelector
NSLog(@"%@\n\n", fractionDescriptor);
UIFont *fracFont = [UIFont fontWithDescriptor:fractionDescriptor size:pointSize];
NSLog(@"fracFont.fontDescriptor: %@\n\n", fracFont.fontDescriptor);
[_label setFont: fracFont];
NSLog(@"label.font.descriptor: %@\n\n", _label.font.fontDescriptor);
}
结果:
这是一个并行的工作示例:https://github.com/mattneub/Programming-iOS-Book-Examples/blob/d649f8bf5dee25a35a72c478d2902896328ca354 /iOS7bookExamples/bk2ch10p499fontDescriptor2/ch23p670font1dynamicType/ViewController.m – matt
谢谢!我永远都看不到。我已经为您的示例添加了针对未来Google Analytics的分数工作代码。 – Lewis42