내보기에 문장을 추가해야합니다. 그러나 그 문장은 아주 크다. 그래서 몇 줄로 정의 된 CGRect 안에 넣고 글꼴 크기를 변경하여 모든 문장을이 CGRect에 표시합니다. 그리고 글꼴 크기는 가능한 한 커야합니다. 여기NSString을 추가하여 사각형 크기를 정의하는 방법
내가 사용하고있는 코드 :
NSAttributedString *sentence = [[NSAttributedString alloc] initWithString:@"The sentence with some words" attributes:@{NSFontAttributeName: wordsFont,NSBackgroundColorAttributeName:[UIColor yellowColor]}];
CGRect sentenceBounds;
sentenceBounds.size = [sentence size];
CGSize neededSize = CGSizeMake(MAX_WIDTH, MAX_HAIGHT);
sentenceBounds.size = neededSize;
sentenceBounds.origin = CGPointMake(0, 0);
[sentence drawInRect:sentenceBounds];
흠 ... 나는 특성 문자열과 크기의 최대 글꼴 크기가 발견 될 때까지 글꼴 크기를 반복적으로 검색하는 코드가 있다고 생각합니다. 웹이나 StackOverflow에서 찾은 코드가 기본이었습니다 (잊어 버렸습니다). 아무도 더 나은 것을 게시하거나 더 나은 해결책이 없다면 나는 그것을 파고 게시 할 것입니다. –