图片拉伸

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

这个方法可以使图片达到拉伸;该方法的意思是意思就是用来创建一个内容可拉伸,而边角不拉伸的图片,需要两个参数,第一个是左边不拉伸区域的宽度,第二个参数是上面不拉伸的高度。那么接下来的一个像素会被拉伸。例如,leftCapHeight为6,topCapHeight为8。那么,图片左边的6个像素,上边的8个像素。不会被拉伸,而左边的第7个像素,上边的第9个像素这一块区域将会被拉伸。剩余的部分也不会被拉伸。

使用案例:

   UIImage *image = [UIImage imageNamed:@"聊天"];

    image = [image stretchableImageWithLeftCapWidth:image.size.width/2 topCapHeight:image.size.height/2];

    

    UIImageView *imageview = [[UIImageView alloc] initWithImage:image];

    imageview.backgroundColor = [UIColor grayColor];

    [imageview setFrame:CGRectMake(50, 100, 300, 50)];

    [self.view addSubview:imageview];

 

posted @ 2017-03-21 15:37  zk·mark  阅读(147)  评论(0编辑  收藏  举报