iOS图片拉伸三种方式

###图片拉伸 ####1.第一种图形界面 第一步 第二步 ######第三步 图形设置只需要点点就行,至于拉伸大小,系统已替你算好 ####2.代码方式

  • 第一种
     UIImageView *imageView=[[UIImageView alloc]init];
     UIImage *image=[UIImage imageNamed:@"chat_send_nor"];
     image=[image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 30) resizingMode:UIImageResizingModeTile];
     imageView.image=image;
     imageView.frame=CGRectMake(30, 50, 200, 200);
     [self.view addSubview:imageView];
    
  • 第二种
    UIImageView *imageView=[[UIImageView alloc]init];
    UIImage *image=[UIImage imageNamed:@"chat_send_nor"];
    

// image=[image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 30) resizingMode:UIImageResizingModeTile]; image=[image stretchableImageWithLeftCapWidth:image.size.width*0.5 topCapHeight:image.size.height]; imageView.image=image; imageView.frame=CGRectMake(30, 50, 200, 200); [self.view addSubview:imageView];

//    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight __TVOS_PROHIBITED;
//    @property(nonatomic,readonly) NSInteger leftCapWidth __TVOS_PROHIBITED;   // default is 0. if non-zero, horiz. stretchable. right cap is calculated as width - leftCapWidth - 1
//    @property(nonatomic,readonly) NSInteger topCapHeight __TVOS_PROHIBITED;   // default is 0. if non-zero, vert. stretchable. bottom cap is calculated as height - topCapWidth - 1
//
//实际就是1,也是图形与图形界面一样的结果
// right = width - left - 1;
// 1 = width - left - right;
// bottom = height - top - 1;
// 1 = height - top - bottom;
//可以将其封装成一个uiimage的分类,这样可以重用
```

####3.github地址 github

转载于:https://my.oschina.net/HYLApple/blog/687291

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值