sizeWithFont : constrainedToSize에 대한 엣지 케이스를 찾았습니다. 망막 디스플레이에서 가끔 한 줄의 높이가 1 줄을 반환합니다. 실제로 필요한 것보다 더 키가 크고 더 중요하게 실제로 끌리는 것보다 큽니다.NSString sizeWithFont : constrainedToSize : 망막 디스플레이에서 잘못된 높이를 반환 함
참고 : 사용중인 실제 코드는 성능 중심의 손으로 그려진 가변 높이 테이블 뷰 셀 코드 안에 묻혀 있으므로 가능한 한 간단한 샘플 코드로 문제를 추출했습니다. (제 질문 이외의 다른 답변을 시도 할 때 참고하십시오 :
이 샘플 UIView는 내용을 채우고 (줄 바꿈) 맞게 텍스트를 측정 한 다음 해당 rect를 채운 다음 텍스트를 그립니다.
망막 장치 (또는 시뮬레이터)에서는 높이가 1 줄로 너무 높지만 망막 이전 장치 (또는 시뮬레이터)에서는 올바른 높이를 반환합니다.
버그 수정이 필요하므로 누구나 가지고있는 통찰력에 대해 크게 감사드립니다!
많은 감사!
-Eric
- (void)drawRect:(CGRect)rect {
NSString * theString = @"Lorem ipsum dolor sit ameyyet, consectetur adipiscing elit. Etiam vel justo leo. Curabitur porta, elit vel.";
UIFont * theFont = [UIFont systemFontOfSize:12];
CGSize theConstraint = CGSizeMake(rect.size.width - 20, rect.size.height - 20);
CGSize theResultSize = [theString sizeWithFont:theFont constrainedToSize:theConstraint];
// dump the measurements
NSLog(@"returned a size h = %f, w = %f", theResultSize.height, theResultSize.width);
// fill the whole rect
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor yellowColor] set];
CGContextFillRect(context, rect);
// fill the measured rect
CGRect theRect = CGRectMake(10, 10, theResultSize.width, theResultSize.height);
context = UIGraphicsGetCurrentContext();
[[UIColor cyanColor] set];
CGContextFillRect(context, theRect);
// draw the text
[[UIColor blackColor] set];
[theString drawInRect:theRect withFont:theFont];
}
전체 간단한 프로젝트는 here 사용할 수 있습니다.
시뮬레이터 이미지 :
http://files.droplr.com/files/9979822/aLDJ.Screen%20shot%202011-01-11%20at%2012%3A34%3A34.png http://files.droplr.com/files/9979822/YpCM.Screen%20shot%202011-01-11%20at%2012%3A36%3A47.png
힘든 일을 그것을 실행했을 때 내가 가진 무엇인가? 누군가 도울 수 있습니까? Tumbleweed 배지는 적립 슈퍼 재미가 아니 었어! – eric
샘플 프로젝트를 실행 한 후에 시뮬레이터 나 SDK의 버그라고 생각합니다. 예, iOS 4.3이 설치된 Xcode 4에는 문제가 없습니다. – cxa
고맙습니다. 현재 Xcode/iOS에서 작동해야합니다. – eric