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에서 사과하려고하면 구문 오류가 발생할 수 있습니다. –