सबसे आसान तरीका शायद NSTextFieldCell
उपclass और -drawInteriorWithFrame:inView:
और -selectWithFrame:inView:editor:delegate:start:length:
ओवरराइड करने का सबसे आसान तरीका है।
आपको यह तय करने की आवश्यकता होगी कि आपकी गिनती के लिए कितनी जगह आवंटित की जाए और संक्षिप्त स्थान में आकर्षित करें। इस उदाहरण कोड की तरह कुछ काम करना चाहिए हालांकि यह एक गोलाकार पाठ क्षेत्र में परीक्षण नहीं किया गया है।
आप एप्पल के PhotoSearch example code में NSCell
उपclassing के बारे में अधिक जानकारी प्राप्त कर सकते हैं।
- (void)drawInteriorWithFrame:(NSRect)bounds inView:(NSView *)controlView {
NSRect titleRect = [self titleRectForBounds:bounds];
NSRect countRect = [self countAreaRectForBounds:bounds];
titleRect = NSInsetRect(titleRect, 2, 0);
NSAttributedString *title = [self attributedStringValue];
NSAttributedString *count = [self countAttributedString];
if (title)
[title drawInRect:titleRect];
[count drawInRect:countRect];
}
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength {
NSRect selectFrame = aRect;
NSRect countRect = [self countAreaRectForBounds:aRect];
selectFrame.size.width -= countRect.size.width + PADDING_AROUND_COUNT;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(__textChanged:) name:NSTextDidChangeNotification object:textObj];
[super selectWithFrame:selectFrame inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
}
- (void)endEditing:(NSText *)editor {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSTextDidChangeNotification object:editor];
[super endEditing:editor];
}
- (void)__textChanged:(NSNotification *)notif {
[[self controlView] setNeedsDisplay:YES];
}
स्रोत
2009-03-22 09:10:16
धन्यवाद मदद के लिए, मुझे लगता है कि कोशिश करेंगे। – Jeena
लिंक टूटा हुआ लगता है – rraallvv
लिंक अब है: https://developer.apple.com/library/prerelease/content/samplecode/PhotoSearch/Introduction/Intro.html – Christophe