方法matlab fill colorColor 是未定义的呢

How to fill color inside UIBezierPath? [如何填充颜色UIBezierPath内?] - 问题-字节技术
How to fill color inside UIBezierPath?
如何填充颜色UIBezierPath内?
问题 (Question)
I draw a shape by UIBezierPath in touchesMoved.
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = [touches anyObject];
secondPoint = firstP
firstPoint = [touch previousLocationInView:self];
currentPoint = [touch locationInView:self];
CGPoint mid1 = midPoint(firstPoint, secondPoint);
CGPoint mid2 = midPoint(currentPoint, firstPoint);
[bezierPath moveToPoint:mid1];
[bezierPath addQuadCurveToPoint:mid2 controlPoint:firstPoint];
[self setNeedsDisplay];
I want to fill RED color inside it after closePath but can't. Please help!
- (void)drawRect:(CGRect)rect
UIColor *fillColor = [UIColor redColor];
[fillColor setFill];
UIColor *strokeColor = [UIColor blueColor];
[strokeColor setStroke];
[bezierPath closePath];
[bezierPath fill];
[bezierPath stroke];
我画一个形状touchesMoved UIBezierPath。-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = [touches anyObject];
secondPoint = firstP
firstPoint = [touch previousLocationInView:self];
currentPoint = [touch locationInView:self];
CGPoint mid1 = midPoint(firstPoint, secondPoint);
CGPoint mid2 = midPoint(currentPoint, firstPoint);
[bezierPath moveToPoint:mid1];
[bezierPath addQuadCurveToPoint:mid2 controlPoint:firstPoint];
[self setNeedsDisplay];
我想填满红色在里面closePath后却不能。请帮助!- (void)drawRect:(CGRect)rect
UIColor *fillColor = [UIColor redColor];
[fillColor setFill];
UIColor *strokeColor = [UIColor blueColor];
[strokeColor setStroke];
[bezierPath closePath];
[bezierPath fill];
[bezierPath stroke];
最佳答案 (Best Answer)
If you have a bezier path stored elsewhere, this should work:
Looking at your edited code, what is happening is that as you are closing the path that you are drawing is getting closed - so you get a line, not a shape since you have only two points.
One way around this is to create the path as your points move, but stroke and fill a copy of that path. For example this is untested code, I'm writing it straight in
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = [touches anyObject];
secondPoint = firstP
firstPoint = [touch previousLocationInView:self];
currentPoint = [touch locationInView:self];
CGPoint mid1 = midPoint(firstPoint, secondPoint);
CGPoint mid2 = midPoint(currentPoint, firstPoint);
[bezierPath moveToPoint:mid1];
[bezierPath addQuadCurveToPoint:mid2 controlPoint:firstPoint];
// pathToDraw is an UIBezierPath * declared in your class
pathToDraw = [[UIBezierPath bezierPathWithCGPath:bezierPath.CGPath];
[self setNeedsDisplay];
And then your drawing code can:
- (void)drawRect:(CGRect)rect {
UIColor *fillColor = [UIColor redColor];
[fillColor setFill];
UIColor *strokeColor = [UIColor blueColor];
[strokeColor setStroke];
// This closes the copy of your drawing path.
[pathToDraw closePath];
// Stroke the path after filling it so that you can see the outline
[pathToDraw fill]; // this will fill a closed path
[pathToDraw stroke]; // this will stroke the outline of the path.
There is some tidying up to do an touchesEnded and this could be made more performant, but you get the idea.
如果你有一个贝塞尔曲线路径存储在其他地方,这应该工作:编辑查看编辑代码,正在发生的事情是,当你关闭路径图越来越封闭,所以你得到一条线,而不是一个形状,因为你只有两个点。一个解决这个问题的办法是创建路径随着你的观点,但中风和填补这条道路的副本。例如这是未测试的代码,我写它直-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = [touches anyObject];
secondPoint = firstP
firstPoint = [touch previousLocationInView:self];
currentPoint = [touch locationInView:self];
CGPoint mid1 = midPoint(firstPoint, secondPoint);
CGPoint mid2 = midPoint(currentPoint, firstPoint);
[bezierPath moveToPoint:mid1];
[bezierPath addQuadCurveToPoint:mid2 controlPoint:firstPoint];
// pathToDraw is an UIBezierPath * declared in your class
pathToDraw = [[UIBezierPath bezierPathWithCGPath:bezierPath.CGPath];
[self setNeedsDisplay];
答案 (Answer) 2
You have to keep array of your UIBezierPaths. Try this code,
- (void)drawRect:(CGRect)rect
for(UIBezierPath *_path in pathArray){
[_path fill];
[_path stroke];
#pragma mark - Touch Methods
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
myPath=[[UIBezierPath alloc]init];
myPath.lineWidth = currentSliderV
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath moveToPoint:[mytouch locationInView:self]];
[pathArray addObject:myPath];
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath addLineToPoint:[mytouch locationInView:self]];
[self setNeedsDisplay];
你必须保持你的数组UIBezierPath年代。试试这个代码, - (void)drawRect:(CGRect)rect
for(UIBezierPath *_path in pathArray){
[_path fill];
[_path stroke];
#pragma mark - Touch Methods
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
myPath=[[UIBezierPath alloc]init];
myPath.lineWidth = currentSliderV
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath moveToPoint:[mytouch locationInView:self]];
[pathArray addObject:myPath];
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath addLineToPoint:[mytouch locationInView:self]];
[self setNeedsDisplay];
本文翻译自StackoverFlow,英语好的童鞋可直接参考原文:[android]方法 fillColor() 是未定义的呢?
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.
CircleOptions circleOptions = new CircleOptions()
.center(new LatLng(latitude, longitude))
.radius(1000); // In meters
.fillColor(Color.RED)
.strokeColor(Color.BLACK)
.strokeWidth(2);
我不断遇到了同样的错误,在填充颜色、 strokeColor 和 strokeWidth
日食不给我任何选项导入任何东西。什么能错了请任何想法吗?
The method fillColor(int) is undefined for the type MainActivity
解决方法 1:
将分号的位置移动到您链的末端。你过早地结束您的语句这就为什么编译器将尝试查找 fillColor() 在 MainActivity 而不是 CircleOptions 。
CircleOptions circleOptions = new CircleOptions()
.center(new LatLng(latitude, longitude))
.radius(1000) // In meters
.fillColor(Color.RED)
.strokeColor(Color.BLACK)
.strokeWidth(2);方法 fillColor 是未定义的呢_百度知道可能未定义_百度知道

我要回帖

更多关于 highcharts fillcolor 的文章

 

随机推荐