聊天气泡拉伸效果

Demo传送门

image.png
- (void)viewDidLoad {
    [super viewDidLoad];

    UIImage *image = [UIImage imageNamed:@"chat_send_nor"];
    
    /**
         ➤方法一
     
         resizingMode:
         UIImageResizingModeTile:平铺模式
         UIImageResizingModeStretch:拉伸模式
     
         resizableImageWithCapInsets:
         上左下右间距,表示的是保护区域。
    
         保护区域:指的是四个圆角我们不想让它拉伸,我们要量出圆角的尺寸,然后设置inset
         只要保护区域正确,模式一和模式二效果是一样的。
     
    */

    //模式一
    image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 30)]; //默认为平铺模式(iOS5.0)
    //模式二
    image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 30) resizingMode:UIImageResizingModeStretch]; //拉伸模式(iOS6.0)
    
    /**
        ➤方法二(这个是比较老的方法,旧项目中可能会遇到)
     
         可以理解成:只拉伸中间1*1的空间,所以传参数左、上时,传图片宽高的一半即可。
     
         根据官方文档:
             1,right cap is calculated as width - leftCapWidth - 1
             2,bottom cap is calculated as height - topCapWidth - 1
     
          left
          top
          width
          height
          right = width - left - 1;
          等价于:1 = width - left - right;
     
          bottom = height - top - 1;
          等价于:1 = height - top - bottom;
    */
//    image = [image stretchableImageWithLeftCapWidth:image.size.width/2 topCapHeight:image.size.height/2];
    
    /**
        方法三:图片必须放在Assets.xcassets中(推荐)
         1,找到Assets.xcassets中的图片,选中
         2,找到slicing模块
         3,设置slices为Horizontal and Vertical
    */
    
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 300)];
    imgView.backgroundColor = [UIColor redColor];
    imgView.image = image;
    
    [self.view addSubview:imgView];
    
}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,458评论 25 709
  • 可用场景 写完上一篇滑动改变Navbar透明度,又想到一个可以关联上的拉伸效果. 比如个人主页,常见的是table...
    XingJin阅读 4,243评论 0 0
  • 人生沒有pause鍵、沒有回頭更沒有砍掉重練。 做過的錯沒有辦法重來,沒有誰要為誰付出,也沒有誰應該為誰勞累。 即...
    桃園王永興阅读 2,523评论 1 1
  • 给你很多的温暖, 在前行的日子里, 一路温暖前行。
    好菇凉啊光芒万丈阅读 1,553评论 0 0
  • 我初初见你 喧嚣里的孤寂 都市的烟火气 勾勒出你的茕茕孑立 我小心翼翼屏住呼吸 想要靠近你 却不敢前移 只能偷偷藏...
    木清悠阅读 1,310评论 0 1

友情链接更多精彩内容