如何使用UIBezierPath或任何其他方法以编程方式在objective-C中创建如下所示的自定义矩形?

时间:2017-01-28 07:25:53

标签: ios objective-c uibezierpath

First custom rectangle

Second custom rectangle

如何创建自定义UIImageview形状,如Rectangle 1,Rectangle 2?提前致谢

1 个答案:

答案 0 :(得分:0)

 UIBezierPath *aPath = [UIBezierPath bezierPath];
    // Set the starting point of the shape.
    if (Flag==0) {
//First rectangle

        [aPath moveToPoint:CGPointMake(0.0, 0.0)];
        // Draw the lines.

        [aPath addLineToPoint:CGPointMake(375.0, 0.0)];

        [aPath addLineToPoint:CGPointMake(367.5, 32.8)];

        [aPath addLineToPoint:CGPointMake(7.5, 32.8)];

           } else {
//Second Rectangle

        [aPath moveToPoint:CGPointMake(7.5, 0.0)];

        [aPath addLineToPoint:CGPointMake(367.5, 0.0)];

        [aPath addLineToPoint:CGPointMake(375, 32.8)];

        [aPath addLineToPoint:CGPointMake(0, 32.8)];

    }

    [aPath closePath];

    return aPath;