UIBezier
オブジェクトを使用してランダムパスを作成するサンプルデモを作成しました。 私は既に質問された同じ種類の質問をしたことを知っていますが、私はそれを解決することができませんでした。異なる色のベジェパスを作成する方法は?
コード
@implementation RandomShape
@synthesize randomPath,size,color;
- (void)drawRect:(CGRect)rect {
self.size = 1.0;
[self.color setStroke];
[self.randomPath stroke];
}
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if(self)
{
self.randomPath = [UIBezierPath bezierPath];
[self.randomPath stroke];
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
[self.randomPath moveToPoint:[touch locationInView:self]];
[self.randomPath setLineWidth:size];
[self setNeedsDisplay];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *mytouch=[touches anyObject];
[self.randomPath addLineToPoint:[mytouch locationInView:self]];
[self setNeedsDisplay];
}
-(void)clearRandomShape
{
self.randomPath = nil; //Set current path nil
self.randomPath = [UIBezierPath bezierPath]; //Create new path
[self.randomPath setLineWidth:2.0];
[self setNeedsDisplay];
}
1)私はピッカービューから色を選択しています。私はそれがあるとして、それはすべての前の行の色を変更ピッカーからカラーを選択した場合> -
今、私の問題は、
です。
(それは私がすべてのランダムなパスで選択した最後の色が表示されます。)
--->私の要件は、私は別の異なる色のランダムなパスをワンドです。
私を混乱させてください。
ありがとうございます。
は、複数のセグメントであなたのラインを描き、あなたの選択に、各セグメントを色付け?私も覚えている[CAGradientLayer](https://developer.apple.com/reference/quartzcore/cagradientlayer)灰色で色を使用することができます –
私の別の要件は、私は別の異なるサイズで描画したいです。しかし、私は変更パスの大きさ私の古いパスの大きさはそのままです。よろしくお願いします。 – hd1344
これはまさに私が意図したことです。ユーザーが 'touchesBegan'で描画するたびに、既存のパスに行を追加するのではなく、そのパスの新しいプロパティで新しいパスを作成します。単一の 'UIBezierPath'の代わりに、' UIBezierPath'を維持し、それを 'Array'します。 Btw、私はswift3でコード化しているので正式な答えを提供していない、私がobjCで謝罪しようとすると構文エラーを起こす可能性がある。 –