UIImage的 stretchableImageWithLeftCapWidth 方法的使用

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

是UIImage的实例函数 , 他的功能是让图片的内容可以进行拉伸而图片的边角不进行拉伸,实现图片的部分拉伸。 给定左边和上边拉伸的边界,在边界之外的部分不会别拉伸,在边界里面的会被拉伸。

例如:[[UIImage imageNamed:@"chat_to"] stretchableImageWithLeftCapWidth:45 topCapHeight:40]  表示图片左边的45像素和图片上边的45像素不会被拉伸,其他区域会被拉伸。当x坐标为46的时候,一个像素就会被横向复制,当y坐标为41的时候,一个像素会被纵向复制。

注意:这个方法只是只是对像素进行复制到一定的高度。

参数1 :左边不被拉伸的区域的像素

参数2 :上边不被拉伸的区域的像素


    //不设置拉伸点,直接设置
    UIImage *image1 = [UIImage imageNamed:@"chat_from"];
    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 100, 170, 170)];
    imageView1.image = image1;
    [self.view addSubview:imageView1];
    
    //设置拉伸点,理解其拉伸效果
    UIImage *image2 = [UIImage imageNamed:@"chat_from"];
    image2 = [image2 stretchableImageWithLeftCapWidth:70 topCapHeight:image2.size.height*0.1];
    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(190, 100, 170, 170)];
    imageView2.image = image2;
    [self.view addSubview:imageView2];



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值