iOS 画气泡
来源:互联网 发布:尚学堂java培训怎么样 编辑:程序博客网 时间:2024/04/30 01:58
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 )];
原文地址:http://www.tuicool.com/articles/qIr2yyF
- iOS 画气泡
- iOS 画地图上的标注气泡
- iOS 气泡聊天效果
- IOS气泡动画教程
- iOS 绘制气泡图案
- iOS制作聊天气泡
- iOS 自定义绘制气泡
- ios 仿微信,短信聊天气泡
- ios 仿微信,短信聊天气泡
- iOS开发 - 气泡控制器 IPAD
- iOS提示气泡,带动画
- iOS 最新仿微信气泡实现
- 气泡
- 气泡
- 气泡
- ios 图片拉伸 产生气泡效果
- iOS 自定义百度地图标注气泡
- ios气泡动画效果的简单实现
- bzoj 1787: [Ahoi2008]Meet 紧急集合(lca)
- Java知识点整理:第七章:static关键字、final关键字、抽象类 、接口、Object类
- HDU2003_求绝对值
- EL表达式
- JS显性数据类型转换和隐性数据类型转换
- iOS 画气泡
- [心得] Effective Java心得笔记
- Ideal 常用快捷键
- python爬虫笔记 --------scrapy框架(4)
- 密码用*表示
- Object.keys方法之详解
- iOS 绘制气泡图案
- 以字节为单位显示变量的内存存储数据
- 云邦互联可以申请免费空间 不错 不相信的可以试试