次のメソッドは、塗りつぶされた三角形の画像を作成する必要がありますが、アウトラインのみを作成します。FILLしないのはなぜですか?これで大騒ぎします。これに苦しんでいる次の貧しい魂がハードルをクリアし、彼らの命を1時間救うことができるように、それが答えられることを願っています.
ここに私が書いた方法があります:
+ (UIImage *)triangleWithSize:(CGSize)imageSize
{
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(context, YES);
// set parameters
CGContextSetLineWidth(context, 1);
CGContextSetStrokeColorWithColor(context, [UIColor yellowColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColor yellowColor].CGColor);
// draw triangle
CGContextBeginPath(context);
CGContextMoveToPoint(context, imageSize.width, 0);
CGContextAddLineToPoint(context, imageSize.width, imageSize.height);
CGContextMoveToPoint(context, imageSize.width, imageSize.height);
CGContextAddLineToPoint(context, 0, imageSize.height / 2);
CGContextMoveToPoint(context, 0, imageSize.height / 2);
CGContextAddLineToPoint(context, imageSize.width, 0);
// CGContextFillPath(context);
// CGContextClosePath(context);
// stroke and fill?
CGContextDrawPath(context, kCGPathFillStroke);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsPopContext();
return image;
}
どんな助けでも大歓迎です。