stretchableImageWithLeftCapWidth用法

stretchableImageWithLeftCapWidth通常用来做图片的局部拉伸,常用的例子是聊天的背景图的部分拉伸

stretchableImageWithLeftCapWidth这个方法 有2个参数
leftCapWidth: 左边不拉伸的像素
topCapHeight:上边不拉伸的像素

例如如下的点:

则取横坐标轴26的像素点横向拉伸到一定宽度
取纵坐标轴11的像素点纵向拉伸到一定长度 (具体长度又imageview的frame决定)
image = [image stretchableImageWithLeftCapWidth:25 topCapHeight:10];

    UIImage *image = [UIImage imageNamed:@"ic_nav_back_dark"];
    UIImageView *view = [[UIImageView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    view.image = image;
    
    view.frame = CGRectMake(60, 60, 100, 100);
    
    [self.view addSubview:view];
    
    
    UIImageView *view1 = [[UIImageView alloc] init];
    view1.backgroundColor = [UIColor whiteColor];
    image = [image stretchableImageWithLeftCapWidth:25 topCapHeight:10];
    view1.image = image;
    
    view1.frame = CGRectMake(60, 300, 100, 100);
    
    [self.view addSubview:view1];
    
    UIImageView *view2 = [[UIImageView alloc] init];
    view2.backgroundColor = [UIColor whiteColor];
    UIImage *image1 = [UIImage imageNamed:@"ic_nav_back_dark"];
    image1 = [image1 stretchableImageWithLeftCapWidth:1 topCapHeight:1];
    view2.image = image1;
    view2.frame = CGRectMake(200, 300, 100, 100);
    [self.view addSubview:view2];

效果如下:

stretchableImageWithLeftCapWidth用法_第1张图片
855CAC19-ED4F-494C-BD32-21D00213D10A.png

你可能感兴趣的:(stretchableImageWithLeftCapWidth用法)