HMSegmentedControl源代码解析(13)
- UID
- 1066743
|
HMSegmentedControl源代码解析(13)
/**
添加背景和border 的layer
@param fullRect cgrect
*/
- (void)addBackgroundAndBorderLayerWithRectCGRect)fullRect {
// Background layer
CALayer *backgroundLayer = [CALayer layer];
backgroundLayer.frame = fullRect;
[self.layer insertSublayer:backgroundLayer atIndex:0];
// Border layer
if (self.borderType & HMSegmentedControlBorderTypeTop) {
CALayer *borderLayer = [CALayer layer];
borderLayer.frame = CGRectMake(0, 0, fullRect.size.width, self.borderWidth);
borderLayer.backgroundColor = self.borderColor.CGColor;
[backgroundLayer addSublayer: borderLayer];
}
if (self.borderType & HMSegmentedControlBorderTypeLeft) {
CALayer *borderLayer = [CALayer layer];
borderLayer.frame = CGRectMake(0, 0, self.borderWidth, fullRect.size.height);
borderLayer.backgroundColor = self.borderColor.CGColor;
[backgroundLayer addSublayer: borderLayer];
}
if (self.borderType & HMSegmentedControlBorderTypeBottom) {
CALayer *borderLayer = [CALayer layer];
borderLayer.frame = CGRectMake(0, fullRect.size.height - self.borderWidth, fullRect.size.width, self.borderWidth);
borderLayer.backgroundColor = self.borderColor.CGColor;
[backgroundLayer addSublayer: borderLayer];
}
if (self.borderType & HMSegmentedControlBorderTypeRight) {
CALayer *borderLayer = [CALayer layer];
borderLayer.frame = CGRectMake(fullRect.size.width - self.borderWidth, 0, self.borderWidth, fullRect.size.height);
borderLayer.backgroundColor = self.borderColor.CGColor;
[backgroundLayer addSublayer: borderLayer];
}
} |
|
|
|
|
|