设置UIImage 圆角
//设置UIImage圆角
@interface UIImage(UIRoundedRectImage)
+ (id) createRoundedRectImage:(UIImage*)image size:(CGSize)size;
@end
@implementation UIImage(UIRoundedRectImage)
static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth,
float ovalHeight)
{
float fw,fh;
if (ovalWidth == 0 || ovalHeight == 0) {
CGContextAddRect(context, rect);
return;
}
CGContextSaveGState(context);
CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextScaleCTM(context, ovalWidth, ovalHeight);
fw = CGRectGetWidth(rect) / ovalWidth;
fh = CGRectGetHeight(rect) / ovalHeight;
CGContextMoveToPoint(context, fw, fh/2); // Start at lower right corner
CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1); // Top right corner
CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner
CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner
CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right
CGContextClosePath(context);
CGContextRestoreGState(context);
}
+ (id) createRoundedRectImage:(UIImage*)image size:(CGSize)size
{
// the size of CGContextRef
int w = size.width;
int h = size.height;
UIImage *img = image;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace,kCGImageAlphaPremultipliedFirst);
CGRect rect = CGRectMake(0, 0, w, h);
CGContextBeginPath(context);
addRoundedRectToPath(context, rect, 5, 5);
CGContextClosePath(context);
CGContextClip(context);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return [UIImage imageWithCGImage:imageMasked];
}
@end
设置UIImage 圆角的更多相关文章
- tableView 获取网络图片,并且设置为圆角(优化,fps)
代码地址如下:http://www.demodashi.com/demo/11088.html 一.准备工作 例子比较精简,没有什么特殊要求,具备Xocde8.0左右版本的就好 二.程序实现 1.相关 ...
- 设置UIImage的渲染模式:UIImage.renderingMode
设置UIImage的渲染模式:UIImage.renderingMode 着色(Tint Color)是iOS7界面中的一个.设置UIImage的渲染模式:UIImage.renderingMode重 ...
- iOS UITabBarItem 选中图的颜色,设置UIimage的渲染模式
UITbarController之前有在这篇文章讲解:http://www.cnblogs.com/niit-soft-518/p/4447940.html 如果自定义了UITabBarItem的图片 ...
- php imagick设置图片圆角的方法
php imagick设置图片圆角的方法 <pre>header('Content-Type: image/png'); $image = new Imagick('http://stat ...
- 设置UICollectionViewCell圆角和阴影
设置cell圆角: cell.contentView.layer.cornerRadius =2.0f; cell.contentView.layer.borderWidth =1.0f; cell. ...
- iOS 中如何将View设置为圆角的矩形?
今天刚好需要添加一个圆角的view. 必须先导入头文件. #import <QuartzCore/QuartzCore.h> bgView.layer.cornerRadius = cor ...
- [转]怎么把一个textview的背景图片设置成圆角的?
在drawable文件夹下新建一个文件设置背景样式代码:在drawable文件夹下面新建text_view_border.xml<?xml version="1.0" ...
- iOS: 使用故事板和xib设置按钮圆角方法
使用storyboard如何设置圆角或边框? 通过storyboard的 运行时属性runtime attribute,可以对Button设置圆角或者边框 1.很多人都知道,通常设置一个 Button ...
- ios中设置UIButton圆角,添加边框
//例如: UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(50, ...
随机推荐
- Mysql笔记——DQL
DQL就是数据查询语言,数据库执行DQL语句不会对数据进行改变,而是让数据库发送结果集给客户端. 语法: SELECTselection_list /*要查询的列名称*/ FROM table_lis ...
- linux 大量的TIME_WAIT解决办法
发现存在大量TIME_WAIT状态的连接tcp 0 0 127.0.0.1:3306 127.0.0.1:41378 TIME ...
- 程序员必须知道的几个国外IT网站
1.TheServerSide 这是一个老牌的IT信息网站,从名称上你就能看出,它是关注服务器端编程的,以Java和Java周边信息为主,不过最近它也有向客户端和微软产品扩展的趋势.这个网站最初是以免 ...
- Ubuntu12.04安装YouCompleteMe插件
以前用的都是ctags+omnicomplete+acp的方式,这次换成clang自解析的方式尝试一把. 自从知道了Vundle,妈妈再也不用担心我麻烦地下插件了 0. 安装必要组件 sudo apt ...
- plsql programming 18 包
所谓包, 就是把一组PL/SQL 的代码元素组织在一个命名空间下. 另外, 包的用法就类似java中的类.( 有封装, 有重载, 没有继承和多肽) create or replace procedur ...
- core--进程
前面我们说了线程是一系列的指令,那么进程是什么呢?进程就是装下这些指令的容器.该容器除了线程,还包含资源等内容.一个进程至少要有一个线程.没有线程的进程就不叫进程 "进程和程序的区别:进程必 ...
- request.getRequestDispatcher()和response.sendRedirect()
request.getRequestDispatcher("/homeMainAction_mainUI.do").forward(getRequest(), getRespons ...
- HDU 2176 (Nim博弈 先手取胜方案) 取(m堆)石子游戏
切切水题,放松心情:-D #include <cstdio> + ; int a[maxn]; int main() { //freopen("in.txt", &qu ...
- 51nod1346 递归
我终于知道我有多么蠢了...推规律根本不带我这么推的...跟51nod那场比赛的傻逼B题一样,想都不想想就打表找规律...智障啊找规律也要按照基本法! //f[1][2]=a[1][2] f[2][1 ...
- 51nod1486 大大走格子
容斥定理+dp...妈呀#1rp耗尽了难怪最近那么衰... #include<cstdio> #include<cstring> #include<cctype> ...