Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS中绘制梯形图形?_Ios_Objective C_Core Graphics - Fatal编程技术网

如何在iOS中绘制梯形图形?

如何在iOS中绘制梯形图形?,ios,objective-c,core-graphics,Ios,Objective C,Core Graphics,我需要帮助在iOS中绘制梯形 我正在使用以下代码绘制粉色形状,但它不起作用: UIBezierPath* trianglePath = [UIBezierPath bezierPath]; [trianglePath moveToPoint:CGPointMake(0, 0)]; [trianglePath addLineToPoint:CGPointMake(topView.frame.size.width, topView.frame.size.height/2)]; [trianglePa

我需要帮助在iOS中绘制梯形

我正在使用以下代码绘制粉色形状,但它不起作用:

UIBezierPath* trianglePath = [UIBezierPath bezierPath];
[trianglePath moveToPoint:CGPointMake(0, 0)];
[trianglePath addLineToPoint:CGPointMake(topView.frame.size.width, topView.frame.size.height/2)];
[trianglePath addLineToPoint:CGPointMake(100, topView.frame.size.height/2)];

CAShapeLayer *triangleMaskLayer = [CAShapeLayer layer];
[triangleMaskLayer setPath:trianglePath.CGPath];

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,topView.frame.size.height-150, 200, 150)];
view.layer.mask = triangleMaskLayer;
[self.view addSubview:view];

如何绘制粉红色的形状?

您没有使用
triangleMaskLayer
。抱歉,键入问题更新了@Larmesry,但您在说什么粉色形状?您没有使用
triangleMaskLayer
。抱歉,键入问题更新了@Larmesry,但您在说什么粉色形状?
-(void)TriangularPinkView{
    UIBezierPath *path = [UIBezierPath bezierPath];
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.strokeColor = [[UIColor redColor] CGColor];
    shapeLayer.lineWidth = 0.5;

    CGPoint start = CGPointMake(CGRectGetMinX(self.pinkView.frame), CGRectGetMidY(self.pinkView.frame)+CGRectGetHeight(self.pinkView.frame)*.25);
    [path moveToPoint:start];
    [path addLineToPoint:CGPointMake(CGRectGetMaxX(self.pinkView.frame), CGRectGetMidY(self.pinkView.frame))];
    [path addLineToPoint:CGPointMake(CGRectGetMaxX(self.pinkView.frame), CGRectGetMaxY(self.pinkView.frame))];
    [path addLineToPoint:CGPointMake(CGRectGetMinX(self.pinkView.frame), CGRectGetMaxY(self.pinkView.frame))];


    shapeLayer.path = [path CGPath];
//    shapeLayer.fillRule = kCAFillRuleEvenOdd;
    shapeLayer.fillColor = [[UIColor redColor] CGColor];

    [self.view.layer addSublayer:shapeLayer];
}