我试图用一些额外的信息覆盖图像:一些文本和矩形。现在我被困在绘制矩形。他们只是不会出现。我究竟做错了什么?正在绘制图像本身,因此图形上下文必须正常。
- (void)drawTag:(NSString *)tag withRect:(CGRect)rect
{
// Set the color in the current graphics context for future draw operations
[[UIColor yellowColor] setStroke];
[[UIColor yellowColor] setFill];
// Create our drawing path
UIBezierPath* drawingPath = [UIBezierPath bezierPathWithRect:rect];
// actually draw it
[drawingPath stroke];
}
- (IBAction)showDetails:(id)sender
{
// draw the image
UIGraphicsBeginImageContext(self.userImage.size);
// This one shows up:
[self.userImage drawAtPoint:CGPointZero];
// This one does not:
[self drawTag:@"Test" withRect:CGRectMake(10, 10, 50, 50)];
// Show the whole thing:
self.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:self.imageViewController animated:YES];
}
答案 0 :(得分:2)
您应该将lineWidth
的{{1}}属性设置为值> = 1