iOS绘制气泡图案

作者: TheRainMan | 来源:发表于2016-01-27 17:13 被阅读2596次

通过重写UIView的DrawRect方法绘制气泡

-(void)drawRect:(CGRect)rect{

[self drawInContext:UIGraphicsGetCurrentContext()];

self.layer.shadowColor = [[UIColor blackColor] CGColor];

self.layer.shadowOpacity = 1.0;

self.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);

}

-(void)drawInContext:(CGContextRef)context

{

CGContextSetLineWidth(context, 2.0);

CGContextSetFillColorWithColor(context, [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0].CGColor);

[self getDrawPath:context];

CGContextFillPath(context);

}

- (void)getDrawPath:(CGContextRef)context

{

CGRect rrect = self.bounds;

CGFloat radius = 6.0;

CGFloat minx = CGRectGetMinX(rrect),

midx = CGRectGetMidX(rrect),

maxx = CGRectGetMaxX(rrect);

CGFloat miny = CGRectGetMinY(rrect),

// midy = CGRectGetMidY(rrect),

maxy = CGRectGetMaxY(rrect)-Arror_height;

CGContextMoveToPoint(context, midx+Arror_height, maxy);

CGContextAddLineToPoint(context,midx, maxy+Arror_height);

CGContextAddLineToPoint(context,midx-Arror_height, maxy);

CGContextAddArcToPoint(context, minx, maxy, minx, miny, radius);

CGContextAddArcToPoint(context, minx, minx, maxx, miny, radius);

CGContextAddArcToPoint(context, maxx, miny, maxx, maxx, radius);

CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);

CGContextClosePath(context);

}


可以实现的效果图:

相关文章

网友评论

  • 与伟大LEE同行:你落下了
    [super drawRect:rect];

    ```
    - (void)drawRect:(CGRect)rect{

    [super drawRect:rect];

    [self drawInContext:UIGraphicsGetCurrentContext()];

    self.layer.shadowColor = [[UIColor blackColor] CGColor];

    self.layer.shadowOpacity = 0.5f;

    self.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
    }
    ```
  • 迷途在成长的路上:怎么给绘制的图形加事件?
  • Dimon_Hu:不错,解决我燃眉之需
  • ryugaku:马克
  • 咖啡凯:👏🏻
  • mark666:用markdown语法

本文标题:iOS绘制气泡图案

本文链接:https://www.haomeiwen.com/subject/jmodkttx.html