NSMatrix에서 버튼을 표시하고 있습니다.NSMatrix의 NSButtonCell에서 텍스트 앞에 이미지 표시
내 요구 사항은 다음과 같습니다 특정 조건이 만족 될 때
는 버튼 제목과 장소 제목의 시작 부분에 이미지의 색상을 변경할 수 있습니다. 위의 코드는 제목의 색 변화를 보여주고있다
// setting attributed text NSAttributedString *selectedCellAttribute; NSFont *selectedCellFont = [NSFont fontWithName:@"Lucida Grande" size:11]; NSColor *selectedCellColor = [NSColor redColor]; NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; [style setAlignment:NSCenterTextAlignment]; // setting image NSTextAttachment *imageAttachment = [[NSTextAttachment alloc] init]; NSCell *cell = [imageAttachment attachmentCell]; [cell setImage:[NSImage imageNamed:@"caution_small.png"]]; NSDictionary *selectedCellDictionary = [NSDictionary dictionaryWithObjectsAndKeys:imageAttachment,NSAttachmentAttributeName,selectedCellFont,NSFontAttributeName,selectedCellColor,NSForegroundColorAttributeName,style,NSParagraphStyleAttributeName,nil]; // recognizing cell NSButtonCell *associatedCell = [associatesMatrix cellAtRow:0 column:2]; selectedCellAttribute = [[NSAttributedString alloc] initWithString:[associatedCell title] attributes:selectedCellDictionary]; [associatedCell setAttributedTitle:selectedCellAttribute];
있지만, 제목 :(
수의 시작 부분에 위치에 이미지를 보여주는 것입니다 :
내가 다음 코드를 사용, 이렇게하려면 누구나 내 요구 사항을 구현하기 위해 잘못되었거나 다른 방법을 제안 할 수 있습니까?
편집 :라인에서: 컴파일 할 때
NSCell *cell = [imageAttachment attachmentCell];
는이 경고를주고있다 :
type 'id <NSTextAttachmentCell>' does not conform to 'NSCopying" protocol.
감사합니다,
Miraaj 당신은 전체 문자열에 대한 첨부 파일을 설정 한
GC를 사용하지 않는 경우 변경 가능한 단락 스타일, 첨부 파일 및 속성이 지정된 문자열을 해제해야합니다. –
답장을 보내 주셔서 감사합니다 ... 응용 프로그램이 GCC를 사용할 수 있습니다! – Devarshi
GC를 원하셨습니까? GCC는 GNU Compiler Collection이며, 사용하는 컴파일러는 무의미합니다. GC는 Objective-C'release' 메시지를 보내는 것이 엄격하게 필요하지 않은 가비지 콜렉션입니다 (하지만 GC를 사용하지 않는다면 "당신은 GC를 사용하지 않는다면 그런 것들을 공개해야합니다"라는 메시지를 알리는 좋은 방법이 아닙니다. 스택 오버플로에 코드를 게시하십시오 (☺). –