2009-03-21 10 views
5

पर "पैडिंग" के साथ NSTextField मैं अपने गोलाकार एनएसटीक्स्टफिल्ड के भीतर "शेष वर्ण नोटिस" दिखाने के लिए प्रयास कर रहा हूं और मुझे इंटरफ़ेस बिल्डर की मदद से दो एनएसटीक्स्टफिल्ड्स के साथ मिला और यह पहले से ही ऐसा लगता है:दाएं

alt text http://jeenaparadies.net/t/s/Twittia-NSTextField1.png

लेकिन जब मैं एक छोटा सा बारे में अधिक यह है कि जैसा दिखता है:

alt text http://jeenaparadies.net/t/s/Twittia-NSTextField2.png

केवल एक चीज मैं के बारे में सोच सकता है NSTextField उपवर्ग है और इसके साथ कुछ करना तो यह डी से है ओएस संख्या के तहत पाठ नहीं खींचते हैं, लेकिन मुझे नहीं पता कि कैसे शुरुआत करें और इसके साथ वास्तव में कुछ मदद की ज़रूरत है।

उत्तर

11

सबसे आसान तरीका शायद 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]; 
} 
+0

धन्यवाद मदद के लिए, मुझे लगता है कि कोशिश करेंगे। – Jeena

+1

लिंक टूटा हुआ लगता है – rraallvv

+1

लिंक अब है: https://developer.apple.com/library/prerelease/content/samplecode/PhotoSearch/Introduction/Intro.html – Christophe

संबंधित मुद्दे