0

以下は、コアグラフィックで描画したいフラグです。

ここに画像の説明を入力

私がすることは:

Flag.m
- (void)drawRect:(CGRect)rect {

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 1.0);

    CGContextMoveToPoint    (context, 20, 10);
    CGContextAddLineToPoint (context, 50, 10);
    CGContextAddLineToPoint (context, 50, 90);
    CGContextAddLineToPoint (context, 45, 90);
    CGContextAddLineToPoint (context, 45, 95);
    CGContextAddLineToPoint (context, 40, 92);
    CGContextAddLineToPoint (context, 35, 90);
    CGContextAddLineToPoint (context, 30, 92);  
    CGContextAddLineToPoint (context, 25, 95);
    CGContextAddLineToPoint (context, 25, 90); 
    CGContextAddLineToPoint (context, 20, 90);  
    CGContextAddLineToPoint (context, 20, 10);    

    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
    CGContextFillPath(context);

}

私が最終的にしているのは以下のとおりです

ここに画像の説明を入力

私の質問 :

旗が折りたたまれて尻尾が丸まっているように見えるように影を追加するにはどうすればよいですか (上の赤い旗のように)

4

1 に答える 1

1

これは比較的単純化されたバージョンです。2 つの部分に分けてビルドするために、いくつかのポイントをコメントアウトしました。しっぽの部分を先に描きます。次に、メインのリボンが上に描画されます。素敵な影の効果は[UIColor colorWithWhite:0.0 alpha:0.4]

もう少し手の込んだものにしたい場合は、メイン エリアの下部のいくつかの点をグラデーション付きの別の四角形として描画します。最後の四角形を描画する前に、必ず影をオフにしてください。

/*CGContextMoveToPoint    (context, 20, 10);
CGContextAddLineToPoint (context, 50, 10);*/
CGContextMoveToPoint    (context, 48, 85);
CGContextAddLineToPoint (context, 48, 90);
CGContextAddLineToPoint (context, 45, 90);
CGContextAddLineToPoint (context, 45, 95);
CGContextAddLineToPoint (context, 40, 92);
CGContextAddLineToPoint (context, 35, 90);
CGContextAddLineToPoint (context, 30, 92);
CGContextAddLineToPoint (context, 25, 95);
CGContextAddLineToPoint (context, 25, 90);
CGContextAddLineToPoint (context, 22, 90);
CGContextAddLineToPoint (context, 22, 85);
//CGContextAddLineToPoint (context, 20, 10);
CGContextSetShadowWithColor(context, CGSizeMake(0, 5.), 3., [UIColor colorWithWhite:0 alpha:.4].CGColor);
CGContextSetFillColorWithColor(context, [UIColor colorWithWhite:.95 alpha:1].CGColor);
CGContextFillPath(context);
CGContextSetShadowWithColor(context, CGSizeMake(0, 2.), 1.5, [UIColor colorWithWhite:0 alpha:.3].CGColor);
CGContextMoveToPoint    (context, 20, 88);
CGContextAddLineToPoint (context, 20, 10);
CGContextAddLineToPoint (context, 50, 10);
CGContextAddLineToPoint (context, 50, 88);
CGContextFillPath(context);
于 2012-08-15T21:01:02.380 に答える