कोको में कुछ खींचने के लिए कुछ कदम हैं।
सबसे पहले आपको उस पथ की आवश्यकता है जिसका उपयोग उस ऑब्जेक्ट को परिभाषित करने के लिए किया जाएगा जिसे आप चित्रित करने जा रहे हैं। कोको में पथ बनाने के लिए यहां एक गाइड के लिए Drawing Fundamental Shapes पर एक नज़र डालें। "NSBezierPath" ऑब्जेक्ट में "appendBezierPathWithOvalInRect" संदेश भेजने में आपको सबसे अधिक दिलचस्पी होगी, यह एक आयत लेता है जो उस मंडल को बाध्य करता है जिसे आप आकर्षित करना चाहते हैं।
इस कोड को एक 10x10 चक्र पैदा करेगा पर 10,10 निर्देशांक:
NSRect rect = NSMakeRect(10, 10, 10, 10);
NSBezierPath* circlePath = [NSBezierPath bezierPath];
[circlePath appendBezierPathWithOvalInRect: rect];
बार जब आप अपने पथ आप वर्तमान ड्राइंग संदर्भ के लिए रंग सेट करना चाहते हैं। दो रंग हैं, स्ट्रोक और भरें; स्ट्रोक पथ की रूपरेखा है और भरना आंतरिक रंग है। एक रंग सेट करने के लिए आप "सेट" को "एनएससीओलर" ऑब्जेक्ट में भेजते हैं।
यह काला करने के लिए स्ट्रोक और लाल रंग के भरण सेट:
[[NSColor blackColor] setStroke];
[[NSColor redColor] setFill];
अब आप अपने पथ है और आप अपने रंग सिर्फ सेट पथ भरें और फिर आकर्षित किया है:
[path stroke];
[path fill];
यह सब एक ग्राफिक्स संदर्भ में किया जाना चाहिए जैसे कि शायद एक दृष्टिकोण के drawRect में।एक साथ एक ग्राफिक्स संदर्भ के साथ यह सब इस प्रकार दिखाई देगा:
- (void)drawRect:(NSRect)rect
{
// Get the graphics context that we are currently executing under
NSGraphicsContext* gc = [NSGraphicsContext currentContext];
// Save the current graphics context settings
[gc saveGraphicsState];
// Set the color in the current graphics context for future draw operations
[[NSColor blackColor] setStroke];
[[NSColor redColor] setFill];
// Create our circle path
NSRect rect = NSMakeRect(10, 10, 10, 10);
NSBezierPath* circlePath = [NSBezierPath bezierPath];
[circlePath appendBezierPathWithOvalInRect: rect];
// Outline and fill the path
[circlePath stroke];
[circlePath fill];
// Restore the context to what it was before we messed with it
[gc restoreGraphicsState];
}
ऐसा लगता है कि यहां तक कि है की तरह ए: BezierPathWithOvalInRect: धन्यवाद! – kdbdallas
हाँ, अगर मुझे सही याद है तो यह तेंदुए में नया है। इससे पहले, पहली चीजों में से एक नेबी कोको प्रोग्रामर (स्वयं सहित) को एक परिपत्र या गोलाकार आयताकार पथ बनाने के लिए एनएसबीज़ियरपाथ में एक श्रेणी परिभाषित करना था। :) –