私は次のコードを持っています:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, 25, 25);
[[button layer] setCornerRadius:5.0f];
[[button layer] setMasksToBounds:YES];
[[button layer] setBackgroundColor:[[UIColor redColor] CGColor]];
[button.titleLabel setFrame:CGRectMake(0,0, 25, 25)];
[button setTitle:[NSString stringWithFormat:@"%@", [[topics objectAtIndex:indexPath.row] unread]] forState:UIControlStateNormal];
問題は、テキスト内の文字列が長くない場合、細かく表示されることです(1〜2桁)。ただし、非常に長い(3 ++桁)場合は、赤いボタンだけが表示され、中にテキストはありません。これをどのように調整しますか?
私はそうは思いません:
[button.titleLabel setAdjustsFontSizeToFitWidth:YES];
仕事はしますか?
titleButton.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)