코코아 NSView에서 가운데 정렬을 사용하여 새로운 라인 (\ n)으로 문자열을 그리려합니다. 예를 들어 내 문자열 인 경우 :코코아 뷰에서 중심 맞춤을 사용하여 텍스트를 그립니다.
가 는NSString * str = @"this is a long line \n and \n this is also a long line";
가 나는 다소 표시이 싶습니다
:
여기this is a long line
and
this is also a long line
는 NSView의의 drawRect 방법 안에 내 코드입니다 :
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setAlignment:NSCenterTextAlignment];
NSDictionary * attributes = [NSDictionary dictionaryWithObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
NSString * mystr = @"this is a long line \n and \n this is also a long line";
[mystr drawAtPoint:NSMakePoint(20, 20) withAttributes:attributes];
그것은 여전히를 그립니다 텍스트가 왼쪽 맞춤으로 표시됩니다. 이 코드의 문제점은 무엇입니까?
는
Garbage Collection을 사용하고 있다면 paragraphStyle이 계속 누출됩니까? – AmaltasCoder
@AAmal 가비지 수집을 사용하는 경우 누출이 없습니다. –