それらの両方裏打ちされた層の背景色を設定するには、UIView
のbackgroundColor
プロパティは、最終的にCALayer
のsetBackgroundColor:(CGColorRef)backgroundColor
メソッドを呼び出します設定しました。
ここにいくつかのヒント、UIViewのsetBackgroundColor:
の呼び出しスタック、それはKDLayer(KDLayerはCALayerのサブクラスです)setBackgroundColorメソッドを呼び出すことがわかります。ここで
![enter image description here](https://i.stack.imgur.com/iMxiN.jpg)
コードで、それはObjective-Cのコードですが、私はそれが理解しやすいと思います。
KDView
サブクラスUIView
@implementation KDView
+ (Class)layerClass {
return [KDLayer class];
}
@end
KDLayer
サブクラスCALayer
@implementation KDLayer
- (void)setBackgroundColor:(CGColorRef)backgroundColor {
[super setBackgroundColor:backgroundColor];
}
@end
KDLayerのsetBackgroundColorでのブレークポイントの追加:メソッドをしてKDViewのインスタンスを作成し、それがbackgroundColor
プロパティの変更。
KDView *v = [KDView new];
v.backgroundColor = [UIColor redColor];