SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
CSS in iOS?
- Keith Norman
Quick about me…
What’s good about CSS?
•

loose coupling between style and content

•

cleaner code

•

makes design changes simple

•

and redesigns feasible (iOS 7?)

•

Come on, does this slide really need to exist?
Bad practice #1: putting style
code in view controllers
textLabel.font
textLabel.textColor
textLabel.backgroundColor

= [UIFont fontWithName:kOpenSansFont size:17];
= RGBCOLOR(51, 51, 51);
= [UIColor clearColor];

=
<p style="font: 15px opensans; color: rgba(51, 51, 51, 1); background: none;"></p>
Bad practice #2: using
Interface Builder
Demo
UIAppearance

Subview
SubSubview
[[UILabel appearance] setTextColor:[UIColor cyanColor]];
[[UILabel appearanceWhenContainedIn:
[Subview class], nil] setTextColor:[UIColor redColor]];
[[UILabel appearanceWhenContainedIn:
[SubSubview class], [Subview class], nil] setTextColor:[UIColor greenColor]];

You can set these up in AppDelegate!
UISearchBar barTintColor UINavigationBar barTintColor
UINavigationBar tintColor
Note: Not “officially” supported by UIAppearance

[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
window tintColor trickles down to all subviews

- (void)tintColorDidChange {
self.backgroundColor = self.tintColor;
}
A bit about font
label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];

Custom font:
UIFontDescriptor *userFont =
[UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
float userFontSize = [userFont pointSize];
UIFont *font = [UIFont fontWithName:@"OpenSans" size:userFontSize];

Bold font:
UIFontDescriptor *descriptor =
[UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleCaption1];
descriptor = [descriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
UIFont *font = [UIFont fontWithDescriptor:descriptor size:0];
[label setFont:font];

https://gist.github.com/nuthatch/7594460
Core Graphics
// PlayPauseButton.h

!
@interface PlayPauseButton : UIControl
!
@property (nonatomic, assign) PlayerState playState;
!
@property (nonatomic, strong) UIColor *controlButtonColor UI_APPEARANCE_SELECTOR;
!
@end

// PlayPauseButton.m

!

- (void)setControlButtonColor:(UIColor *)controlButtonColor {
_controlButtonColor = controlButtonColor;
[self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, self.controlButtonColor.CGColor);
// ... draw icon ... //
}

PaintCode App (for learning Core Graphics)
http://www.paintcodeapp.com/
Theme + “styleClass”
Bold
Not Bold
<p class="strong">Lost At Sea</p>
<p>The Squirrel Nut Zippers</p>
- (void)awakeFromNib {
self.albumName.styleClass = @"strongLabel";
}

[some magic happens]
and the text is bold
StyleClass Category
//

UIView+StyleClass.h

!
@interface UIView (StyleClass)
!
@property (nonatomic, strong) NSString
!

*styleClass;

@end

//

UIView+StyleClass.m

!
@implementation UIView
!
@dynamic styleClass;
!

(StyleClass)

- (void)setStyleClass:(NSString *)styleClass {
NSString *selectorName = [@"style" stringByAppendingString:[NSString stringWithFormat:@“%@%@:",
[[styleClass substringToIndex:1] uppercaseString], [styleClass substringFromIndex:1]]];
SEL sel = NSSelectorFromString(selectorName);
if (class_getClassMethod([Theme class], sel) != NULL) {
[Theme performSelector:sel withObject:self];
}
}

!

@end
Theme class

@implementation Theme

!

+ (void)styleStrongLabel:(UILabel *)label {
UIFontDescriptor *descriptor =
[UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleCaption1];
descriptor = [descriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
UIFont *font = [UIFont fontWithDescriptor:descriptor size:0];
[label setFont:font];
}

!

@end
menuItem.styleClass = @"myCollectionMenuItem";
menuItem.styleClass = @"recentlyPlayedMenuItem";
UIView+CSS
(highly experimental)
@interface UIView (CSS)

!

@property
@property
@property
@property
@property

!

(nonatomic,
(nonatomic,
(nonatomic,
(nonatomic,
(nonatomic,

strong)
strong)
strong)
strong)
strong)

CSSBorder *border UI_APPEARANCE_SELECTOR;
CSSBorder *borderTop UI_APPEARANCE_SELECTOR;
CSSBorder *borderBottom UI_APPEARANCE_SELECTOR;
CSSDropshadow *dropShadow UI_APPEARANCE_SELECTOR;
CSSBorderRadius *borderRadius UI_APPEARANCE_SELECTOR;

@end

CSSBorderRadius *borderRadius = [[CSSBorderRadius alloc] init];
borderRadius.radius = 15.0f;
[[AlbumCard appearance] setBorderRadius:borderRadius];
Further reading
Classy - https://github.com/cloudkite/Classy
UISS - https://github.com/robertwijas/UISS
WWDC 2012 #216 and 2013 #214!
https://developer.apple.com/wwdc/videos/
Record Collection!
https://github.com/keithnorm/RecordCollection
Style vs. Content and Clean Theming in iOS

Contenu connexe

Similaire à Style vs. Content and Clean Theming in iOS

CodeStock :: Introduction To MacRuby and HotCocoa
CodeStock :: Introduction To MacRuby and HotCocoaCodeStock :: Introduction To MacRuby and HotCocoa
CodeStock :: Introduction To MacRuby and HotCocoaDoc Norton
 
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)anistar sung
 
Programming iOS in C#
Programming iOS in C#Programming iOS in C#
Programming iOS in C#Frank Krueger
 
Tools and practices for rapid application development
Tools and practices for rapid application developmentTools and practices for rapid application development
Tools and practices for rapid application developmentZoltán Váradi
 
iOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEEiOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEEHendrik Ebel
 
AppDevKit for iOS Development
AppDevKit for iOS DevelopmentAppDevKit for iOS Development
AppDevKit for iOS Developmentanistar sung
 
iPhone/iPad开发讲座 第五讲 定制视图和多点触摸
iPhone/iPad开发讲座 第五讲 定制视图和多点触摸iPhone/iPad开发讲座 第五讲 定制视图和多点触摸
iPhone/iPad开发讲座 第五讲 定制视图和多点触摸Hao Peiqiang
 
Creating an Uber Clone - Part III - Transcript.pdf
Creating an Uber Clone - Part III - Transcript.pdfCreating an Uber Clone - Part III - Transcript.pdf
Creating an Uber Clone - Part III - Transcript.pdfShaiAlmog1
 
用 IBDesignable 作 UI
用 IBDesignable 作 UI用 IBDesignable 作 UI
用 IBDesignable 作 UITsungyu Yu
 
Cocoa Heads Tricity - Design Patterns
Cocoa Heads Tricity - Design PatternsCocoa Heads Tricity - Design Patterns
Cocoa Heads Tricity - Design PatternsMaciej Burda
 
Creating an Uber Clone - Part IX - Transcript.pdf
Creating an Uber Clone - Part IX - Transcript.pdfCreating an Uber Clone - Part IX - Transcript.pdf
Creating an Uber Clone - Part IX - Transcript.pdfShaiAlmog1
 
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...Applitools
 
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter LuhBuilding Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter LuhFITC
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .netStephen Lorello
 
XebiConFr 15 - Brace yourselves Angular 2 is coming
XebiConFr 15 - Brace yourselves Angular 2 is comingXebiConFr 15 - Brace yourselves Angular 2 is coming
XebiConFr 15 - Brace yourselves Angular 2 is comingPublicis Sapient Engineering
 
Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2dVinsol
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Pritam Samanta
 

Similaire à Style vs. Content and Clean Theming in iOS (20)

CodeStock :: Introduction To MacRuby and HotCocoa
CodeStock :: Introduction To MacRuby and HotCocoaCodeStock :: Introduction To MacRuby and HotCocoa
CodeStock :: Introduction To MacRuby and HotCocoa
 
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
 
Programming iOS in C#
Programming iOS in C#Programming iOS in C#
Programming iOS in C#
 
Tools and practices for rapid application development
Tools and practices for rapid application developmentTools and practices for rapid application development
Tools and practices for rapid application development
 
iOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEEiOS Einführung am Beispiel von play NEXT TEE
iOS Einführung am Beispiel von play NEXT TEE
 
AppDevKit for iOS Development
AppDevKit for iOS DevelopmentAppDevKit for iOS Development
AppDevKit for iOS Development
 
004
004004
004
 
iPhone/iPad开发讲座 第五讲 定制视图和多点触摸
iPhone/iPad开发讲座 第五讲 定制视图和多点触摸iPhone/iPad开发讲座 第五讲 定制视图和多点触摸
iPhone/iPad开发讲座 第五讲 定制视图和多点触摸
 
Creating an Uber Clone - Part III - Transcript.pdf
Creating an Uber Clone - Part III - Transcript.pdfCreating an Uber Clone - Part III - Transcript.pdf
Creating an Uber Clone - Part III - Transcript.pdf
 
用 IBDesignable 作 UI
用 IBDesignable 作 UI用 IBDesignable 作 UI
用 IBDesignable 作 UI
 
Cocoa Heads Tricity - Design Patterns
Cocoa Heads Tricity - Design PatternsCocoa Heads Tricity - Design Patterns
Cocoa Heads Tricity - Design Patterns
 
Core animation
Core animationCore animation
Core animation
 
Creating an Uber Clone - Part IX - Transcript.pdf
Creating an Uber Clone - Part IX - Transcript.pdfCreating an Uber Clone - Part IX - Transcript.pdf
Creating an Uber Clone - Part IX - Transcript.pdf
 
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...Visual Component Testing  -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
 
iOS
iOSiOS
iOS
 
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter LuhBuilding Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .net
 
XebiConFr 15 - Brace yourselves Angular 2 is coming
XebiConFr 15 - Brace yourselves Angular 2 is comingXebiConFr 15 - Brace yourselves Angular 2 is coming
XebiConFr 15 - Brace yourselves Angular 2 is coming
 
Game development with Cocos2d
Game development with Cocos2dGame development with Cocos2d
Game development with Cocos2d
 
Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game Computer Project For Class XII Topic - The Snake Game
Computer Project For Class XII Topic - The Snake Game
 

Dernier

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Dernier (20)

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Style vs. Content and Clean Theming in iOS

  • 1. CSS in iOS? - Keith Norman
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. What’s good about CSS? • loose coupling between style and content • cleaner code • makes design changes simple • and redesigns feasible (iOS 7?) • Come on, does this slide really need to exist?
  • 9. Bad practice #1: putting style code in view controllers textLabel.font textLabel.textColor textLabel.backgroundColor = [UIFont fontWithName:kOpenSansFont size:17]; = RGBCOLOR(51, 51, 51); = [UIColor clearColor]; = <p style="font: 15px opensans; color: rgba(51, 51, 51, 1); background: none;"></p>
  • 10. Bad practice #2: using Interface Builder
  • 11. Demo
  • 12. UIAppearance Subview SubSubview [[UILabel appearance] setTextColor:[UIColor cyanColor]]; [[UILabel appearanceWhenContainedIn: [Subview class], nil] setTextColor:[UIColor redColor]]; [[UILabel appearanceWhenContainedIn: [SubSubview class], [Subview class], nil] setTextColor:[UIColor greenColor]]; You can set these up in AppDelegate!
  • 14. UINavigationBar tintColor Note: Not “officially” supported by UIAppearance [[UINavigationBar appearance] setTintColor:[UIColor redColor]];
  • 15. window tintColor trickles down to all subviews - (void)tintColorDidChange { self.backgroundColor = self.tintColor; }
  • 16. A bit about font label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; Custom font: UIFontDescriptor *userFont = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody]; float userFontSize = [userFont pointSize]; UIFont *font = [UIFont fontWithName:@"OpenSans" size:userFontSize]; Bold font: UIFontDescriptor *descriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleCaption1]; descriptor = [descriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; UIFont *font = [UIFont fontWithDescriptor:descriptor size:0]; [label setFont:font]; https://gist.github.com/nuthatch/7594460
  • 17. Core Graphics // PlayPauseButton.h ! @interface PlayPauseButton : UIControl ! @property (nonatomic, assign) PlayerState playState; ! @property (nonatomic, strong) UIColor *controlButtonColor UI_APPEARANCE_SELECTOR; ! @end // PlayPauseButton.m ! - (void)setControlButtonColor:(UIColor *)controlButtonColor { _controlButtonColor = controlButtonColor; [self setNeedsDisplay]; } - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, self.controlButtonColor.CGColor); // ... draw icon ... // } PaintCode App (for learning Core Graphics) http://www.paintcodeapp.com/
  • 18. Theme + “styleClass” Bold Not Bold <p class="strong">Lost At Sea</p> <p>The Squirrel Nut Zippers</p>
  • 19. - (void)awakeFromNib { self.albumName.styleClass = @"strongLabel"; } [some magic happens] and the text is bold
  • 20. StyleClass Category // UIView+StyleClass.h ! @interface UIView (StyleClass) ! @property (nonatomic, strong) NSString ! *styleClass; @end // UIView+StyleClass.m ! @implementation UIView ! @dynamic styleClass; ! (StyleClass) - (void)setStyleClass:(NSString *)styleClass { NSString *selectorName = [@"style" stringByAppendingString:[NSString stringWithFormat:@“%@%@:", [[styleClass substringToIndex:1] uppercaseString], [styleClass substringFromIndex:1]]]; SEL sel = NSSelectorFromString(selectorName); if (class_getClassMethod([Theme class], sel) != NULL) { [Theme performSelector:sel withObject:self]; } } ! @end
  • 21. Theme class @implementation Theme ! + (void)styleStrongLabel:(UILabel *)label { UIFontDescriptor *descriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleCaption1]; descriptor = [descriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold]; UIFont *font = [UIFont fontWithDescriptor:descriptor size:0]; [label setFont:font]; } ! @end
  • 23. UIView+CSS (highly experimental) @interface UIView (CSS) ! @property @property @property @property @property ! (nonatomic, (nonatomic, (nonatomic, (nonatomic, (nonatomic, strong) strong) strong) strong) strong) CSSBorder *border UI_APPEARANCE_SELECTOR; CSSBorder *borderTop UI_APPEARANCE_SELECTOR; CSSBorder *borderBottom UI_APPEARANCE_SELECTOR; CSSDropshadow *dropShadow UI_APPEARANCE_SELECTOR; CSSBorderRadius *borderRadius UI_APPEARANCE_SELECTOR; @end CSSBorderRadius *borderRadius = [[CSSBorderRadius alloc] init]; borderRadius.radius = 15.0f; [[AlbumCard appearance] setBorderRadius:borderRadius];
  • 24. Further reading Classy - https://github.com/cloudkite/Classy UISS - https://github.com/robertwijas/UISS WWDC 2012 #216 and 2013 #214! https://developer.apple.com/wwdc/videos/ Record Collection! https://github.com/keithnorm/RecordCollection