なぜかわからないのですが?ただし、テキストでカスタムフォントを使用NSAttributedString
するとsizeToFit
、文字列内の特定の文字がクリップされます。
コードサンプルは次のとおりです。
NSString *appTitle = @"Hemang";
NSString *appQuote = @" My name last char is g";
NSString *mergedString = [NSString stringWithFormat:@"%@\n%@",appTitle,appQuote];
UILabel *label1 = [[UILabel alloc] init];
label1.frame = CGRectMake(0, 0, 200.f, 80.f);
NSMutableAttributedString *firstLabelAttributes = [[NSMutableAttributedString alloc] initWithString:mergedString];
NSMutableParagraphStyle *paragrapStyle = NSMutableParagraphStyle.new;
paragrapStyle.alignment = NSTextAlignmentLeft;
[firstLabelAttributes addAttribute:NSParagraphStyleAttributeName value:paragrapStyle range:NSMakeRange(0, [mergedString length])];
[firstLabelAttributes addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"NexaBold" size:50.f]
range:NSMakeRange(0, [appTitle length])];
[firstLabelAttributes addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"NexaLight" size:10.f]
range:NSMakeRange([appTitle length]+1, [appQuote length])];
[label1 setNumberOfLines:2];
[label1 setAttributedText:firstLabelAttributes];
[self.view addSubview:label1];
[label1 sizeToFit];
label1.center = self.view.center;
アップデート :
通常の私の別のテストでは
label1.text = @"Hemang"
[label1 sizeToFit];
g クリップ
更新 2:
一時的な回避策は、sizeToFit
呼び出し後に高さを増やすことです。
CGRect frame = label1.frame
frame.size.height += 5;
label1.frame = frame;
それは私の問題を解決しましたが、私はこのパッチの平和を本当に望んでいません。