iphone图片拉伸相关

关于让图片在指定位置拉伸,有一个函数

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

 (支持ios2--ios4)

这个函数是UIImage的一个实例函数,它的功能是创建一个内容可拉伸,而边角不拉伸的图片,需要两个参数,第一个是左边不拉伸区域的宽度,第二个参数是上面不拉伸的高度。根据设置的宽度和高度,将接下来的一个像素进行左右扩展和上下拉伸。

注意:可拉伸的范围都是距离leftCapWidth后的1竖排像素,和距离topCapHeight后的1横排像素。

以上函数在apple官方文档中定义为(Deprecated in iOS 5.0),虽经验证在5.0.1上可以使用并不报错,不过推荐在IOS5上使用以下函数:

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets

 (仅支持ios5)

 

相关代码:

UIImage *bg = [[UIImage imageNamed:@"camera.png"]stretchableImageWithLeftCapWidth:30 topCapHeight:0];

UIImageView *bgView = [[UIImageView alloc] initWithImage:bg];

bgView.frame = CGRectMake(100, 200, 160, 60);

[self.view addSubview:bgView];

[bg release];

[bgView release];

 

UIImage *bg = [[UIImageimageNamed:@"camera.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];

UIImageView *bgView = [[UIImageView alloc] initWithImage:bg];

bgView.frame = CGRectMake(100, 200, 160, 60);

[self.view addSubview:bgView];

[bg release];

[bgView release];

 

参考网页https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImage_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UIImage/stretchableImageWithLeftCapWidth:topCapHeight:

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/occ/instm/UIImage/resizableImageWithCapInsets:



转载:http://www.cnblogs.com/ydhliphonedev/archive/2012/03/17/2403213.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值