原创 ios绘制 圆形气泡

效果:

1 先自定义一个view

#import <UIKit/UIKit.h>

#define kCalloutWidth   80.0   //气泡高度

#define kCalloutHeight  95.0   //气泡宽度

#define kArrorHeight    15      //底部距离高度

@interface CallOutContentView : UIView

@end

2实现代码

#import "CallOutContentView.h"

@implementation CallOutContentView

- (instancetype)initWithFrame:(CGRect)frame {

if (self = [super initWithFrame:frame]) {

self.backgroundColor = [UIColor clearColor];

}

return self;

}

#pragma mark - draw rect

- (void)drawRect:(CGRect)rect{

  [self drawInContext:UIGraphicsGetCurrentContext()];

  self.layer.shadowColor = [[UIColor clearColor] 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:0.000 green:0.251 blue:0.502 alpha:1.000].CGColor); //气泡填充色

[self getDrawPath:context];

}

//气泡背景绘制

- (void)getDrawPath:(CGContextRef)context

{

CGRect rrect = self.bounds;

CGFloat radius = (kCalloutHeight - kArrorHeight) / 2.0;

CGFloat midx = CGRectGetMidX(rrect);

CGFloat maxy = CGRectGetMaxY(rrect) - kArrorHeight;//调节离底部的位置

CGFloat midy = maxy /2.0;

CGContextSaveGState(context); //保存上下文 1

CGContextBeginPath(context);

//底部三角

CGContextMoveToPoint(context, midx + kArrorHeight, maxy);

CGContextAddLineToPoint(context, midx, maxy + kArrorHeight);

CGContextAddLineToPoint(context, midx - kArrorHeight, maxy);

CGContextFillPath(context); //渲染三角形

CGContextRestoreGState(context); //还原上下文 1

CGContextAddArc(context, midx, midy + 5, radius, 0, M_PI*2, 1);//画圆

CGContextFillPath(context); //渲染圆形

CGContextClosePath(context);

}

@end

3 创建实例

CallOutContentView *callOutView = [[CallOutContentView alloc]initWithFrame:CGRectMake(0, 0, kCalloutWidth, kCalloutHeight)];

时间: 2024-10-18 13:52:46

原创 ios绘制 圆形气泡的相关文章

android开发步步为营之58:给图片绘制圆形气泡背景效果

最近在开发项目的时候,有一个需求,需要给应用图标绘制圆形气泡背景,有了彩色气泡这样显得漂亮一点,气泡的颜色是应用图标的颜色均值,先看看效果,然后,我再给出demo. demo应用图标是这样的: 添加气泡背景后是这样的: 仔细看圆形背景颜色是图标颜色的均值. 好的,下面我们来完成这个demo. 第一步.编写页面activity_drawcycle.xml <?xml version="1.0" encoding="utf-8"?> <LinearLa

在DrawingVisual上绘制圆形的进度条,类似于IOS系统风格。

1.说明:在WPF中,文件下载时需要显示下载进度,由于系统自带的条型进度条比较占用空间,改用圆形的进度条,需要在DrawingVisual上呈现. 运行的效果如图: private Point GetPointOnCir(Point CenterPoint, double r, double angel) { Point p = new Point(); p.X = Math.Sin(angel * Math.PI / 180) * r + CenterPoint.X; p.Y = Center

iOS中绘制圆形的函数方法

- (void)drawRect:(CGrect)rect { CGRect bounds = self.bounds;//根据bounds计算中心点 CGPoint center;  //圆心定位屏幕的中心 center.x = bounds.origin.x + bounds.size.width / 2.0;  //分别计算屏幕的长河宽,进行比较,因为绘制的圆形不应该超出屏幕的界限,以较短的那个的一半作为半径 center.y = bounds.origin.y + bounds.size

Breaseman算法绘制圆形|中点算法绘制圆形_程序片段

Breaseman算法绘制圆形|中点算法绘制圆形_程序片段 1. Breaseman算法绘制圆形程序 由于算法的特殊性,限制绘制第一象限部分,其他部分通过旋转绘制. 1 void CCGProjectWorkView::bresenHam_1P4Circle(int radium, const float lineColor[]) 2 { 3 int pointX, pointY, deltD, deltHD, deltDV, direction; 4 pointX = 0; 5 pointY

项目中遇到的问题-2:编译第三方静态库报错、查看静态库的类型、绘制圆形

这一周比较折腾,由于项目应用涉及到和其他产品线APP的互相通信,在高层领导英(yi)明(ta)神(hu)武(tu)的战略指导下,我开始了与其他组同事的联调之旅.这几天鄙司负责产品的上级同事莅临监工,对现在的情况又提出了一些改进,作为一名程序猿,我已经奉上我的双膝... 一.集成公司其他组的.a静态库,报错:duplicate symbole for architectecture i386 XXX  查了一下报错的地方,都是指示.a的库和工程里面某些.m文件冲突,正好同事提到之前有碰到过这种情况

SkylineGlobe 如何实现绘制圆形Polygon和对图层的圆形范围选择查询

//结束绘制圆形之前,得到Polygon var pos = gPolyObj.Position; var bufferR = gPolyObj.Radius; var cVerticesArray = [-122.415025, 37.76059, 10, ]; var point = sgworld.Creator.GeometryCreator.CreatePointGeometry(cVerticesArray); point.X = pos.X; point.Y = pos.Y; po

绘制圆形椭圆

/**绘制圆形*/ CGContextRef contextRef=UIGraphicsGetCurrentContext(); CGContextAddArc(contextRef, 150, 300, 100, 0, 3.14*2, 0); CGContextStrokePath(contextRef); /**绘制椭圆*/ CGContextAddEllipseInRect(contextRef, CGRectMake(50, 400, 200, 100)); CGContextStrok

【程序吧 www.qhttl.com 圆形气泡导航特效jquery】

先上图: jquery实现的圆形气泡特效,是导航类的,用于大气的网页设计,或者公司网站首页导航特效 预览地址:程序吧推介圆形气泡导航特效 下载地址:圆形气泡导航特效 [程序吧 www.qhttl.com 圆形气泡导航特效jquery],布布扣,bubuko.com

html5 canvas绘制圆形印章,以及与页面交互

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>HTML5 Canvas画印章</title> 6 <script type="text/javascript" src="../JQmain/jquery-2.2.0.min.js"></script> 7 &l