114 Customizing the Appearance of Uikit Controls

Post on 08-Mar-2015

2,285 views 3 download

transcript

These are confidential sessions—please refrain from streaming, blogging, or taking pictures

Session 114

Customizing the Appearanceof UIKit Controls

Chris ParkeriOS Frameworks Engineer

1

2

3

4

Tint color

5

Tint color

6

Tint color

7

8

Images

9

setBackgroundImage:forBarMetrics:

typedef enum { UIBarMetricsDefault, UIBarMetricsLandscapePhone,} UIBarMetrics;

10

titleTextAttributes:

leftBarButtonItems:rightBarButtonItems:

leftItemsSupplementBackButton

11

titleTextAttributes:

leftBarButtonItems:rightBarButtonItems:

leftItemsSupplementBackButton

12

titleTextAttributes:

leftBarButtonItems:rightBarButtonItems:

leftItemsSupplementBackButton

13

setBackgroundImage:forState:barMetrics:

setBackButtonBackgroundImage:forState:barMetrics:

14

setBackgroundImage:forState:barMetrics:

setBackButtonBackgroundImage:forState:barMetrics:

15

Customizing instancesDemo

Marian GoldeeniOS Frameworks Mountain Biker

16

Writing customization API is difficult

17

Using customization API is difficult

18

Consistent look

Easy

Support application features

19

20

[aSlider setMinimumTrackTintColor:[UIColor redColor]];

21

[[UISlider appearance] setMinimumTrackTintColor:[UIColor redColor]];

22

[[UISlider appearance] setMinimumTrackTintColor:[UIColor redColor]];

23

[[UISlider appearance] setMinimumTrackTintColor:[UIColor redColor]];

24

Appearance ProxyUIAppearance.h

@protocol UIAppearance <NSObject>

+ (id)appearance;...

@end

25

Appearance ProxyUIAppearance.h

@protocol UIAppearance <NSObject>

+ (id)appearance;...

@end

#define UI_APPEARANCE_SELECTOR

26

Appearance proxy basicsDemo

27

Zap

28

Zap

29

Appearance ProxyUIAppearance.h

@protocol UIAppearance <NSObject>

+ (id)appearance;+ (id)appearanceWhenContainedIn:(Class<UIAppearanceContainer>)containerClass, ...;

@end

30

Appearance ProxyUIAppearance.h

@protocol UIAppearance <NSObject>

+ (id)appearance;+ (id)appearanceWhenContainedIn:(Class<UIAppearanceContainer>)containerClass, ...;

@end

31

Containment

[[UIButton appearanceWhenContainedIn: [UINavigationController class], nil] setTitleColor:[UIColor redColor] forControlState:UIControlStateNormal];

32

Containment

[[UIButton appearanceWhenContainedIn: [UINavigationController class], nil] setTitleColor:[UIColor redColor] forControlState:UIControlStateNormal];

33

Zap

34

Zap

35

Containment

[[UIButton appearanceWhenContainedIn: [CustomViewController class], [UINavigationController class], nil] setTitleColor:[UIColor redColor] forControlState:UIControlStateNormal];

36

Zap

37

Zap

38

ContainmentComposition rules

The button’s appearance……when contained in a CustomViewController…when contained in a UINavigationController

[[UIButton appearanceWhenContainedIn: [CustomViewController class], [UINavigationController class], nil] setTitleColor:[UIColor redColor] forControlState:UIControlStateNormal];

39

ContainmentDemo

40

What is Happening?Rule application

• Just before -[UIView layoutSubviews] is called…■ Rules are evaluated■ Customizations are applied

•Updates are applied at the time the hierarchy is changed■ At the hierarchy change point■ Does not update in real time

41

Zap

42

Zap[ setTitleColor: [UIColor greenColor] forControlState: UIControlStateNormal];

43

Zap

44

Zap

45

[[UISlider appearance] setMinimumTrackTintColor:[UIColor redColor]];

46

Zap

47

Zap

48

49

Bill DudneyApplication Frameworks Evangelistdudney@apple.com

DocumentationiOS Dev Centerhttp://developer.apple.com/devcenter/ios/

Apple Developer Forumshttp://devforums.apple.com

More Information

50

51