У меня возникли проблемы с отображением фракций в Objective C, хотя эквивалентный код работает в Swift. Мне нужно пропустить что-то очень очевидное?Создание дескрипторов шрифтов с фракциями в объекте C
Swift Code:
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)")
}
Результат:
эквивалентный код в Objective 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
СПАСИБО! Я бы никогда этого не видел. Я добавил рабочий код для фракций к вашему примеру для будущих гуглеров. – Lewis42