Ios 为什么现金支付者';s笔划伸出框架?
下面是示例代码:Ios 为什么现金支付者';s笔划伸出框架?,ios,objective-c,core-animation,Ios,Objective C,Core Animation,下面是示例代码: //Called by VC: HICircleView *circleView = [[HICircleView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; // init of circle view - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { CAShape
//Called by VC:
HICircleView *circleView = [[HICircleView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
// init of circle view
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
CAShapeLayer *borderLayer = [CAShapeLayer layer];
borderLayer.fillColor = [UIColor whiteColor].CGColor;
borderLayer.path = [UIBezierPath bezierPathWithOvalInRect:self.frame].CGPath;
borderLayer.strokeColor = [[UIColor redColor] CGColor];
borderLayer.lineWidth = 5;
[self.layer addSublayer:borderLayer];
}
return self;
}
好的,谢谢你的回答。第一班:
CGRect rect = CGRectMake(3, 3, self.frame.size.width, self.frame.size.height);
borderLayer.path = [UIBezierPath bezierPathWithOvalInRect:rect].CGPath;
并使线宽为6。
< P>设置<代码>线宽绘制一条线,其中实际路径正好在绘制线的中间。 如果希望绘制的线与某个对象对齐,则必须将路径移动一半的线宽
您可以使用UIBezierPath
上的-(void)applyTransform:(cgafinetransform)transform
移动路径,并应用平移变换
如果希望绘制的路径包含在某个区域中,则移动路径没有帮助。在这种情况下,只需创建一个较小的路径。如果要绘制线宽为5的100ptx100pt矩形,则必须在95pt*95pt矩形中绘制路径(两侧各有2.5pt的空间)。您最好选择视图的边界属性进行计算。如果框架属性的原点大于(0,0),它将无法正常工作。可以使用CGRectInsets调整圆的矩形,而不是执行变换计算。这将自动将矩形定位在原始矩形的中心
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
CAShapeLayer *borderLayer = [CAShapeLayer layer];
borderLayer.fillColor = [UIColor whiteColor].CGColor;
CGFloat lineWidth = 5;
CGRect rect = CGRectInset(self.bounds, lineWidth / 2, lineWidth / 2);
borderLayer.path = [UIBezierPath bezierPathWithOvalInRect:rect].CGPath;
borderLayer.strokeColor = [[UIColor redColor] CGColor];
borderLayer.lineWidth = lineWidth;
[self.layer addSublayer:borderLayer];
}
return self;
}
谢谢你能解释一下如何移动线路路径吗?不要介意。明白了。感谢CGRectInset提示,这就是我在Swift 3中得到的结果:
let delta=type(of:self)。StrokeLineWidth/2.0
let rect=contentView.bounds.insetBy(dx:delta,dy:delta)