- (void)makeLineInImageView:(UIImageView *)imageView
{
UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //設定線條終點形狀
float lengths[] = {2, 2}; //第一個參數設定每個虛線寬度,第二個參數設定虛線的間隔
CGContextRef line = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(line, [UIColor grayColor].CGColor);
CGContextSetLineDash(line, 0, lengths, 2);
CGContextMoveToPoint(line, 0.0f, 0.0f); //開始畫線
CGContextAddLineToPoint(line, imageView.frame.size.width, 0.0f);
CGContextStrokePath(line);
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
}
沒有留言:
張貼留言