在动态值在 iOS 的图形中绘制三角形

Draw a triangle in a graph with dynamic values in iOS

我想绘制一个具有动态值的三角形,底边向下,锐边向上。我该怎么做?

这应该可以做到。

- (void)drawRect:(CGRect)rect {
    //This set the line color
    [[UIColor blueColor] setStroke];

    [[UIColor redColor] setFill];
     UIBezierPath *path = [UIBezierPath bezierPath];
    //Starting point
    [path moveToPoint:CGPointMake(0, 0)];
    //Vertice one
    [path addLineToPoint:CGPointMake(1, 1)];
    //Vertice two
    [path addLineToPoint:CGPointMake(0, 1)];

    [path closePath];

    //fill path with the defined color
    [path fill];
    //draw the stroke with the defined color
    [path stroke];

}