NSMatrix にボタンを表示しています。
私の要件は次のとおりです。
特定の条件を満たしたときに、ボタンのタイトルの色を変更し、タイトルの先頭に画像を配置します。
そのために、次のコードを使用しました。
// 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.
ありがとう、
ミラージュ