图片size ---- width:248 - height:259UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 100, 300, 300)]; CGSize size = [UIImage imageNamed:@"test"].size; NSLog(@"---- width:%.0f - height:%.0f",size.width,size.height); imgView.image = [[UIImage imageNamed:@"test"] resizableImageWithCapInsets:UIEdgeInsetsMake(100, 100, 100, 100) resizingMode:UIImageResizingModeTile]; [self.view addSubview:imgView];
拉伸后的显示结果
UIEdgeInsetsMake(100, 100, 100, 100) 是相对原图来讲的 (width:248 - height:259),相对原图的这个范围内的内容被拉伸。边缘受到保护。
- UIImageResizingModeStretch:拉伸模式,通过拉伸UIEdgeInsets指定的矩形区域来填充图片
- UIImageResizingModeTile:平铺模式,通过重复显示UIEdgeInsets指定的矩形区域来填充图片