0
Swiftで同等のコードが機能していても、Objective Cの小数部の表示に問題があります。私は何か非常に明白な行方不明でなければならない?Objective Cの小数点を含むフォント記述子の作成
スウィフトコード:
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
ありがとうございます!私はそれを見たことがないだろう。私は今後のグーグルのためにあなたの例に分数のための作業コードを追加しました。 – Lewis42