iOS UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用
来源:互联网 发布:云盘搭建php源码 编辑:程序博客网 时间:2024/05/15 21:00
原文链接:http://www.2cto.com/kf/201507/419729.html
简介:有时候我们只是想把图片部分拉伸,而不是全部拉伸,那么就要用到下面这个函数,并附上实例验证
1
2
3
<code
class
=
"hljs"
objectivec=
""
> - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
//leftCapWidth:左边不拉伸区域
//topCapHeight:上面不拉伸区域</code>
对距离leftCapWidth的1竖排像素,和具体topCapHeight的1横排像素进行拉伸,其它像素不拉伸
练习一:理解拉伸点,左边和上面分开设置,从效果图来理解。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<code
class
=
"hljs"
objectivec=
""
> self.view.backgroundColor = [UIColor darkGrayColor];
//不设置拉伸点,直接设置
UIImage *image1 = [UIImage imageNamed:
@QQ
];
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(
10
,
100
,
170
,
170
)];
imageView1.image = image1;
[self.view addSubview:imageView1];
//设置拉伸点,对左边和上面分开设置,理解其拉伸效果
UIImage *image2 = [UIImage imageNamed:
@QQ
];
image2 = [image2 stretchableImageWithLeftCapWidth:
0
topCapHeight:image2.size.height*
0.5
];
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(
190
,
100
,
170
,
170
)];
imageView2.image = image2;
[self.view addSubview:imageView2];</code>
效果图
横向拉伸:
1
2
<code avrasm=
""
class
=
"hljs"
> image2 = [image2 stretchableImageWithLeftCapWidth:image2.size.width*
0.5
topCapHeight:
0
];
</code>
效果图:
练习二:最近做到一个聊天框的联系,对文字背景图片的拉伸应用,左边的小三角我不希望拉伸,拉伸影响美观,只拉伸右边方框部分,那么调用此函数就可以实现,这个较为常用。
1
2
3
4
5
6
7
8
9
10
11
12
<code
class
=
"hljs"
objectivec=
""
>
//不设置拉伸点,直接设置
UIImage *image1 = [UIImage imageNamed:
@chat
];
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(
100
,
100
,
200
,
80
)];
imageView1.image = image1;
[self.view addSubview:imageView1];
//设置拉伸点
UIImage *image2 = [UIImage imageNamed:
@chat
];
image2 = [image2 stretchableImageWithLeftCapWidth:image2.size.width*
0.5
topCapHeight:image2.size.width*
0.8
];
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(
100
,
200
,
200
,
80
)];
imageView2.image = image2;
[self.view addSubview:imageView2];</code>
效果图:
0 0
- iOS UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用
- UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用
- UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用
- UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用
- iOS开发 ☞ UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用
- IOS图片拉伸的方法 UIImage stretchableImageWithLeftCapWidth:leftCapWidth:topCapHeight
- iOS图片拉伸技巧—— resizableImageWithCapInsets/stretchableImageWithLeftCapWidth
- iOS图像拉伸,stretchableImageWithLeftCapWidth
- iOS图像拉伸,stretchableImageWithLeftCapWidth
- iOS 图像拉伸,stretchableImageWithLeftCapWidth
- iOS图像拉伸,stretchableImageWithLeftCapWidth
- UIImage的 stretchableImageWithLeftCapWidth 方法的使用
- 图片拉伸处理:stretchableImageWithLeftCapWidth方法的使用
- IOS uiimage 拉伸的方法
- iOS图像拉伸,stretchableImageWithLeftCapWidth:topCapHeight:
- UIImage图片部分拉伸
- ios之图片的拉伸、UIImageView的stretchableImageWithLeftCapWidth方法详解
- IOS开发UIImage中stretchableImageWithLeftCapWidth方法的解释
- 《追风筝的人》读后感
- Android自定义控件:上拉刷新下拉加载的滑动控件
- c# 中关于sql数据库的视图和数据字典的使用有感~
- 程序员面试切忌的10大错误
- http与https的区别
- iOS UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用
- Activity的生命周期
- 图标字体制作工具栏
- centos 升级python2.6 到python3.3
- SQL 分页支持查询 ROW_NUMBER() OVER (ORDER BY ReportID) AS RowNo_
- php linux 安装 phalcon扩展
- python连接mysql数据库
- spring入门例子
- android API