다음 코드가 있습니다.
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)
