标题:
HMSegmentedControl源代码解析(13)
[打印本页]
作者:
look_w
时间:
2019-2-19 17:42
标题:
HMSegmentedControl源代码解析(13)
/**
添加背景和border 的layer
@param fullRect cgrect
*/
- (void)addBackgroundAndBorderLayerWithRect
CGRect)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];
}
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0