使用核心图形创建带轮廓的图像

时间:2015-07-25 09:06:41

标签: ios objective-c xcode ios8 core-graphics

我需要帮助才能创建类似于此的图像:

enter image description here

1 个答案:

答案 0 :(得分:1)

如果您创建UIView的子类,例如CustomView,您唯一需要做的就是实施drawRect:方法:

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];

    // set fill & stroke color
    [[UIColor blueColor] setStroke];
    [[UIColor purpleColor] setFill];

    // create blocks
    CGFloat blockWidth = self.bounds.size.width / 3;
    CGFloat blockHeight = self.bounds.size.height;
    for (int i = 0; i < 3; i++) {
        UIBezierPath *path = [UIBezierPath bezierPathWithRect:
            CGRectMake(blockWidth * i, 0, blockWidth, blockHeight);
        path.lineWidth = 2;
        [path fill];
        [path stroke];
    }
}