tôi đã có thể vẽ một hộp tiêu tan, sử dụng đoạn mã sau:vẽ tiêu tan dòng sử dụng CALayer
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
CGRect shapeRect = CGRectMake(0.0f, 0.0f, 200.0f, 100.0f);
[shapeLayer setBounds:shapeRect];
[shapeLayer setPosition:CGPointMake(self.coreImageView_.frameX, self.coreImageView_.frameBottom - self.coreImageView_.frameHeight/2)];
[shapeLayer setFillColor:[[UIColor clearColor] CGColor]];
[shapeLayer setStrokeColor:[[UIColor whiteColor] CGColor]];
[shapeLayer setLineWidth:2.0f];
[shapeLayer setLineJoin:kCALineJoinRound];
[shapeLayer setLineDashPattern:
[NSArray arrayWithObjects:[NSNumber numberWithInt:5],
[NSNumber numberWithInt:5],
nil]];
Bây giờ nếu tôi muốn chỉ cần vẽ một đường gạch gạch từ điểm X đến điểm B, làm thế nào tôi nên sửa đổi mã này?
ý bạn là gì bởi điểm X và điểm B? họ là điểm trên hình chữ nhật của bạn hoặc họ chỉ là 2 điểm bất cứ nơi nào trên màn hình? –
Có thể trùng lặp [tại đây] (http://stackoverflow.com/questions/12091916/uiview-with-a-dashed-line) –
http://stackoverflow.com/questions/12091916/uiview-with-a-dashed- line/12092002 # 12092002 –