1.图片拉伸
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
参数解释:
leftCapWidth,拉伸image左边开始的第(leftCapWidth + 1)个像素,该像素左边和右边的其他像素不被影响
topCapHeight,拉伸image上边开始的第(topCapHeight + 1)个像素,该像素上边和下边的其他像素不被影响
原图:
通过 stretchImg方法拉伸后的效果截图:
实现代码:
<pre name="code" class="objc">#pragma mark 拉伸图片
-(void)stretchImg
{
UIImage *img = [UIImage imageNamed:@"Head@2x.png"];
img = [img stretchableImageWithLeftCapWidth:35 topCapHeight:25.0];
UIImageView *imageView = [[UIImageView alloc]initWithImage:img];
[imageView setFrame:CGRectMake(50, 50, 200, 200)];
[self.view addSubview:imageView];
}