三种方式
1
垂直方向拉伸
2代码制作
UIImageView *imageView = [[UIImageView alloc]init]; UIImage *image = [UIImage imageNamed:@"popover_background"];
imageView.image = [image stretchableImageWithLeftCapWidth:<#(NSInteger)#> topCapHeight:<#(NSInteger)#>]
imageView.image = [image stretchableImageWithLeftCapWidth:image.size.width* 0.5 topCapHeight:image.size.height* 0.5];
imageView.size = CGSizeMake(100, 100);
UIWindow *window = [UIApplication sharedApplication].keyWindow; [window addSubview:imageView];
第三种 UIImageView *imageView = [[UIImageView alloc]init]; UIImage *image = [UIImage imageNamed:@"popover_background"]; imageView.image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(20, 0, 20, 0) resizingMode:UIImageResizingModeStretch]; imageView.size = CGSizeMake(100, 100); UIWindow *window = [UIApplication sharedApplication].keyWindow; [window addSubview:imageView];
*拉伸模式指定方式:
*直接在资源文件里面指定
*resizableImageWithCapInsets
*stretchableImageWithLeftCapWidth