Skip to content

Instantly share code, notes, and snippets.

@xiangyuan
Created July 26, 2012 09:55
Show Gist options
  • Save xiangyuan/3181284 to your computer and use it in GitHub Desktop.
Save xiangyuan/3181284 to your computer and use it in GitHub Desktop.
UIimage的拉伸扩展
UIImage *rawBackground = [UIImage imageNamed:@"picture"];
UIImage *background = [rawBackground stretchableImageWithLeftCapWidth:13 topCapHeight:22];
UIImageView *imageView = [[UIImageView alloc] initWithImage:background];
imageView.frame = CGRectMake(0, 0, containerView.frame.size.width, containerView.frame.size.height);
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
stretchableImageWithLeftCapWidth topCapHeight 这个方法是指 不拉伸区域到左边的距离 第二个参数 不拉伸区域到上边的距离。
ios后这个方法过时了使用resizableImageWithCapInsets
如果参数指定10,5。那么,图片左边10个像素,上边5个像素。不会被拉伸,x坐标为11和一个像素会被横向复制,y坐标为6的一个像素会被纵向复制。注意:只是对一个像素进行复制到一定宽度。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment