美文网首页
关于IOS图片拉伸处理

关于IOS图片拉伸处理

作者: 哔哩哔哩智能喵 | 来源:发表于2016-09-22 16:02 被阅读137次
  • 如果想要拉伸一个图片,直接拉伸的话,图片有透明的区域会拉伸变形,需要设置保护的区域方法可以分为两种
    1. 通过代码
  UIImageView *imageView =[[UIImageView alloc]init];
    imageView.frame = CGRectMake(10, 10, 200, 100);
    [self.view addSubview:imageView];
    //加载原图
    UIImage *image =[UIImage imageNamed:@"chat_send_press_pic"];
    
    //拉伸处理 UIEdgeInsetsMake 需要保护的区域
//    image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 30) resizingMode:UIImageResizingModeStretch];
//    imageView.image = image;
    
    /**
     *  一个图片有上下左右位置,stretchableImageWithLeftCapWidth方法是算出1*1的像素不保护
     * leftCapWidth :width - left - right - 1
     * topCapHeight :height - top - bottom - 1
     */
    image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
    
    imageView.image = image;
  1. 在Assset文件中设置



相关文章

网友评论

      本文标题:关于IOS图片拉伸处理

      本文链接:https://www.haomeiwen.com/subject/dfmzettx.html