ios - 关于Layer层问题,为什么 Debug View Hierarchy 下不是整个填充视图?
ringa_lee
ringa_lee 2017-04-17 15:16:52
[iOS讨论组]

我自定义了一个BWLabel,主要实现画三条边框,重写了draw方法
- (void)drawRect:(CGRect)rect {

CGRect frame = self.frame;

UIBezierPath *linePath = [UIBezierPath bezierPath];

[linePath moveToPoint:CGPointMake(0, 0)];
[linePath addLineToPoint:CGPointMake(frame.size.width, 0)];
[linePath addLineToPoint:CGPointMake(frame.size.width, frame.size.height)];
[linePath addLineToPoint:CGPointMake(0, frame.size.height)];

CAShapeLayer *lineLayer = [CAShapeLayer layer];
lineLayer.backgroundColor = [[UIColor whiteColor] CGColor];
lineLayer.lineWidth= self.lineWidth;
lineLayer.strokeColor = [self.strokeColor CGColor];
lineLayer.path = linePath.CGPath;
lineLayer.fillColor = [self.fillColor CGColor];

[self.layer addSublayer:lineLayer];

}

出于好奇,我使用 Debug View Hierarchy 去查看视图层次,发现,在 Debug View Hierarchy 上layer并不是整个填充Label。我之后又尝试用UILabel,设置背景色,也发现同样的问题,我很好奇,这是为什么?

ringa_lee
ringa_lee

ringa_lee

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号