SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
Custom UI for OS X 
by Dmitry Obukhov 
for CocoaHeads Moscow with ♥
Custom UI 
• Modify the Look and Feel 
• Change and extend behaviour 
• Create new controls from 
scratch
Application Kit 
...the modern framework for building great apps!
NSView 
NSView & Custom Drawing 
- (void)drawRect:(NSRect)dirtyRect 
{ 
// Your drawing code here 
} 
NSResponder & Custom Behaviour 
– (void)mouseDown/Dragged/Up/Moved/Entered/Exited:(NSEvent 
*)theEvent; 
– (void)scrollWheel:(NSEvent *)theEvent; 
– (void)keyDown/Up:(NSEvent *)theEvent;
NSControl 
NSCell 
+ (Class)cellClass; 
+ (void)setCellClass:(Class)class; 
– (id)cell; 
– (void)setCell:(NSCell *)aCell; 
NSCell : NSObject<NSCoding, NSCopying, NSUserInterfaceItemIdentification> 
The NSCell class provides a mechanism for displaying text or images in an NSView object without the 
overhead of a full NSView subclass. It’s used heavily by most of the NSControl classes to implement 
their internal workings.
NSCell 
NSCell 
NSButtonCell 
NSMenuItemCell 
NSPopUpButtonCell 
NSControl 
NSButton 
NSPopUpButton 
... 
NSSegmentedControlCell 
NSTextFieldCell 
NSSliderCell 
...
NSButtonCell 
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 
{ 
[self drawBezelWithFrame:cellFrame inView:controlView]; 
[self drawInteriorWithFrame:cellFrame inView:controlView]; 
} 
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 
{ 
[self drawImage:self.image 
withFrame:[self imageRectForBounds:cellFrame] 
inView:controlView]; 
[self drawTitle:self.attributedStringValue 
withFrame:[self titleRectForBounds:cellFrame] 
inView:controlView]; 
}
- (void)drawBezelWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 
{ 
// Draw background and border here 
} 
- (void)drawImage:(NSImage *)image withFrame:(NSRect)frame inView:(NSView 
*)controlView 
{ 
// Draw image here 
} 
- (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame 
inView:(NSView *)controlView 
{ 
// Draw title here 
} 
NSButtonCell
- (void)drawSegment:(NSInteger)segment inFrame:(NSRect)frame withView: 
(NSView *)controlView 
{ 
// Draw segment background and border here 
} 
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 
{ 
// Draw control background and border here 
} 
NSSegmentedCell
Cocoa Drawing 
CGNS
Cocoa Drawing
- (void)drawRect:(NSRect)dirtyRect 
{ 
static NSGradient *glassGradient = nil; 
if (glassGradient == nil) { 
glassGradient = [[NSGradient alloc] initWithColorsAndLocations: 
[NSColor colorWithCalibratedWhite:(253.0 / 255.0) alpha:1.0], 0.0, 
[NSColor colorWithCalibratedWhite:(242.0 / 255.0) alpha:1.0], 0.45, 
[NSColor colorWithCalibratedWhite:(230.0 / 255.0) alpha:1.0], 0.45, 
[NSColor colorWithCalibratedWhite:(230.0 / 255.0) alpha:1.0], 1.0, 
nil]; 
} 
[NSGraphicsContext saveGraphicsState]; 
[[NSColor windowFrameColor] set]; 
NSRectFill(self.bounds); 
NSRect backgroundRect = NSMakeRect(0.0, 0.0, 
NSWidth(self.bounds), 
NSHeight(self.bounds) - 1.0); 
[glassGradient drawInRect:backgroundRect angle:-90.0]; 
[NSGraphicsContext restoreGraphicsState]; 
} 
Cocoa Drawing
Tips & Tricks
Performance 
•Use less views 
•Draw less 
- (void)drawRect:(NSRect)dirtyRect; 
- (BOOL)inLiveResize; 
- (BOOL)preservesContentDuringLiveResize; 
•Be opaque 
- (BOOL)isOpaque; 
•Cache 
- (void)cacheImageInRect:(NSRect)rect;
State & Behaviour 
•Enabled/Disabled 
- (BOOL)isEnabled; 
•Focus 
- (BOOL)becomeFirstResponder; 
•Active/Inactive 
- (BOOL)isKeyWindow; 
•Someone uses a graphite theme 
- (NSControlTint)currentControlTint; 
- (NSColor *)colorForControlTint:(NSControlTint)tint;
Thanks! 
Dmitry Obukhov 
stel2k@gmail.com

Weitere ähnliche Inhalte

Mehr von CocoaHeads

Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев
Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис ЛебедевВстреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев
Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис ЛебедевCocoaHeads
 
Встреча №9. AudioBus: Эволюция звука, Данил Пархоменко
Встреча №9. AudioBus: Эволюция звука, Данил ПархоменкоВстреча №9. AudioBus: Эволюция звука, Данил Пархоменко
Встреча №9. AudioBus: Эволюция звука, Данил ПархоменкоCocoaHeads
 
Встреча №8. NSIncrementalStore, или как заставить Core Data варить ваш собств...
Встреча №8. NSIncrementalStore, или как заставить Core Data варить ваш собств...Встреча №8. NSIncrementalStore, или как заставить Core Data варить ваш собств...
Встреча №8. NSIncrementalStore, или как заставить Core Data варить ваш собств...CocoaHeads
 
Встреча №8. RESTful клиент — это просто. Тонкости использования RestKit, Миха...
Встреча №8. RESTful клиент — это просто. Тонкости использования RestKit, Миха...Встреча №8. RESTful клиент — это просто. Тонкости использования RestKit, Миха...
Встреча №8. RESTful клиент — это просто. Тонкости использования RestKit, Миха...CocoaHeads
 
Встреча №8. Использование возможностей iOS 7 SDK, Ксения Покровская
Встреча №8. Использование возможностей iOS 7 SDK, Ксения ПокровскаяВстреча №8. Использование возможностей iOS 7 SDK, Ксения Покровская
Встреча №8. Использование возможностей iOS 7 SDK, Ксения ПокровскаяCocoaHeads
 
Встреча №5. Взаимодействие между дизайнерами и разработчиками, Евгений Беляев
Встреча №5. Взаимодействие между дизайнерами и разработчиками, Евгений БеляевВстреча №5. Взаимодействие между дизайнерами и разработчиками, Евгений Беляев
Встреча №5. Взаимодействие между дизайнерами и разработчиками, Евгений БеляевCocoaHeads
 
Встреча №5. Можно ли сделать дизайн без дизайнера? Александр Киров
Встреча №5. Можно ли сделать дизайн без дизайнера? Александр КировВстреча №5. Можно ли сделать дизайн без дизайнера? Александр Киров
Встреча №5. Можно ли сделать дизайн без дизайнера? Александр КировCocoaHeads
 
Встреча №5. Звук и ресурсы iOS в realtime, Константин Платов
Встреча №5. Звук и ресурсы iOS в realtime, Константин ПлатовВстреча №5. Звук и ресурсы iOS в realtime, Константин Платов
Встреча №5. Звук и ресурсы iOS в realtime, Константин ПлатовCocoaHeads
 

Mehr von CocoaHeads (8)

Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев
Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис ЛебедевВстреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев
Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев
 
Встреча №9. AudioBus: Эволюция звука, Данил Пархоменко
Встреча №9. AudioBus: Эволюция звука, Данил ПархоменкоВстреча №9. AudioBus: Эволюция звука, Данил Пархоменко
Встреча №9. AudioBus: Эволюция звука, Данил Пархоменко
 
Встреча №8. NSIncrementalStore, или как заставить Core Data варить ваш собств...
Встреча №8. NSIncrementalStore, или как заставить Core Data варить ваш собств...Встреча №8. NSIncrementalStore, или как заставить Core Data варить ваш собств...
Встреча №8. NSIncrementalStore, или как заставить Core Data варить ваш собств...
 
Встреча №8. RESTful клиент — это просто. Тонкости использования RestKit, Миха...
Встреча №8. RESTful клиент — это просто. Тонкости использования RestKit, Миха...Встреча №8. RESTful клиент — это просто. Тонкости использования RestKit, Миха...
Встреча №8. RESTful клиент — это просто. Тонкости использования RestKit, Миха...
 
Встреча №8. Использование возможностей iOS 7 SDK, Ксения Покровская
Встреча №8. Использование возможностей iOS 7 SDK, Ксения ПокровскаяВстреча №8. Использование возможностей iOS 7 SDK, Ксения Покровская
Встреча №8. Использование возможностей iOS 7 SDK, Ксения Покровская
 
Встреча №5. Взаимодействие между дизайнерами и разработчиками, Евгений Беляев
Встреча №5. Взаимодействие между дизайнерами и разработчиками, Евгений БеляевВстреча №5. Взаимодействие между дизайнерами и разработчиками, Евгений Беляев
Встреча №5. Взаимодействие между дизайнерами и разработчиками, Евгений Беляев
 
Встреча №5. Можно ли сделать дизайн без дизайнера? Александр Киров
Встреча №5. Можно ли сделать дизайн без дизайнера? Александр КировВстреча №5. Можно ли сделать дизайн без дизайнера? Александр Киров
Встреча №5. Можно ли сделать дизайн без дизайнера? Александр Киров
 
Встреча №5. Звук и ресурсы iOS в realtime, Константин Платов
Встреча №5. Звук и ресурсы iOS в realtime, Константин ПлатовВстреча №5. Звук и ресурсы iOS в realtime, Константин Платов
Встреча №5. Звук и ресурсы iOS в realtime, Константин Платов
 

Kürzlich hochgeladen

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Kürzlich hochgeladen (20)

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 

Встреча №1. Разработка кастомных контролов для OS X, Дмитрий Обухов

  • 1. Custom UI for OS X by Dmitry Obukhov for CocoaHeads Moscow with ♥
  • 2. Custom UI • Modify the Look and Feel • Change and extend behaviour • Create new controls from scratch
  • 3. Application Kit ...the modern framework for building great apps!
  • 4. NSView NSView & Custom Drawing - (void)drawRect:(NSRect)dirtyRect { // Your drawing code here } NSResponder & Custom Behaviour – (void)mouseDown/Dragged/Up/Moved/Entered/Exited:(NSEvent *)theEvent; – (void)scrollWheel:(NSEvent *)theEvent; – (void)keyDown/Up:(NSEvent *)theEvent;
  • 5. NSControl NSCell + (Class)cellClass; + (void)setCellClass:(Class)class; – (id)cell; – (void)setCell:(NSCell *)aCell; NSCell : NSObject<NSCoding, NSCopying, NSUserInterfaceItemIdentification> The NSCell class provides a mechanism for displaying text or images in an NSView object without the overhead of a full NSView subclass. It’s used heavily by most of the NSControl classes to implement their internal workings.
  • 6. NSCell NSCell NSButtonCell NSMenuItemCell NSPopUpButtonCell NSControl NSButton NSPopUpButton ... NSSegmentedControlCell NSTextFieldCell NSSliderCell ...
  • 7. NSButtonCell - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { [self drawBezelWithFrame:cellFrame inView:controlView]; [self drawInteriorWithFrame:cellFrame inView:controlView]; } - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { [self drawImage:self.image withFrame:[self imageRectForBounds:cellFrame] inView:controlView]; [self drawTitle:self.attributedStringValue withFrame:[self titleRectForBounds:cellFrame] inView:controlView]; }
  • 8. - (void)drawBezelWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { // Draw background and border here } - (void)drawImage:(NSImage *)image withFrame:(NSRect)frame inView:(NSView *)controlView { // Draw image here } - (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView { // Draw title here } NSButtonCell
  • 9. - (void)drawSegment:(NSInteger)segment inFrame:(NSRect)frame withView: (NSView *)controlView { // Draw segment background and border here } - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { // Draw control background and border here } NSSegmentedCell
  • 12. - (void)drawRect:(NSRect)dirtyRect { static NSGradient *glassGradient = nil; if (glassGradient == nil) { glassGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithCalibratedWhite:(253.0 / 255.0) alpha:1.0], 0.0, [NSColor colorWithCalibratedWhite:(242.0 / 255.0) alpha:1.0], 0.45, [NSColor colorWithCalibratedWhite:(230.0 / 255.0) alpha:1.0], 0.45, [NSColor colorWithCalibratedWhite:(230.0 / 255.0) alpha:1.0], 1.0, nil]; } [NSGraphicsContext saveGraphicsState]; [[NSColor windowFrameColor] set]; NSRectFill(self.bounds); NSRect backgroundRect = NSMakeRect(0.0, 0.0, NSWidth(self.bounds), NSHeight(self.bounds) - 1.0); [glassGradient drawInRect:backgroundRect angle:-90.0]; [NSGraphicsContext restoreGraphicsState]; } Cocoa Drawing
  • 14. Performance •Use less views •Draw less - (void)drawRect:(NSRect)dirtyRect; - (BOOL)inLiveResize; - (BOOL)preservesContentDuringLiveResize; •Be opaque - (BOOL)isOpaque; •Cache - (void)cacheImageInRect:(NSRect)rect;
  • 15. State & Behaviour •Enabled/Disabled - (BOOL)isEnabled; •Focus - (BOOL)becomeFirstResponder; •Active/Inactive - (BOOL)isKeyWindow; •Someone uses a graphite theme - (NSControlTint)currentControlTint; - (NSColor *)colorForControlTint:(NSControlTint)tint;
  • 16. Thanks! Dmitry Obukhov stel2k@gmail.com