iOS开发自己尝试等装一下iOS Developer

iOS绘制气泡图案

2016-01-27  本文已影响2596人  TheRainMan

通过重写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);

}


可以实现的效果图:

上一篇下一篇

猜你喜欢

热点阅读