UIImage *normalImage = [UIImage imageNamed:@"xx.png"]; //ios5以前实现拉伸图片指定位置的方法 UIImage *newImage = [normalImage stretchableImageWithLeftCapWidth: normalImage.size.width / 2 topCapHeight:normalImage.size.height / 2]; // stretchableImageWithLeftCapWidth: topCapHeight:该方法可以返回一张拉伸指定位置的图片. //LeftCapWidth:左边多大的距离不可以拉伸(水平方向) //topCapHeight:上边有多大的距离不可以拉伸(垂直方法) //1 = width - leftCapWidth - right //1 = height - topCapWidth - bottom //ios5 //指定图片的上边,下边,左边,右边 多少距离是不可以拉伸的,默认的拉伸方案是平铺 CGFloat w = norImage.size.width; CGFloat h = norImage.size.height; UIImage *newImage = [norImage resizableImageWithCapInsets:UIEdgeInsetsMake(h * 0.5, w * 0.5, h * 0.5 , w * 0.5)]; //ios6 //相比IOS5的方法,多了一个指定拉伸模式的参数: //参数有两种:平铺, 拉伸 CGFloat w = norImage.size.width * 0.5; CGFloat h = norImage.size.height * 0.5; UIImage *newImage = [norImage resizableImageWithCapInsets:UIEdgeInsetsMake(h, w, h, w) resizingMode:UIImageResizingModeStretch];
时间: 2024-10-05 04:22:59