如何在iPhone应用程序中仅缩放图像的特定部分? [英] How to scale only specific parts of image in iPhone app?

查看:128
本文介绍了如何在iPhone应用程序中仅缩放图像的特定部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iPhone应用程序中缩放图像但不完全。我只想缩放特定部分,如底部或中间部分......我该怎么做?

I want to scale the image in iPhone app but not entirely. I just want to scale specific parts like the bottom part or the middle part...How do I do it?

请帮忙。

谢谢

推荐答案

听起来你想做一个9切片缩放形式或3-切片缩放。假设您有以下图片:

It sounds like you want to do a form of 9-slice scaling or 3-slice scaling. Let's say you have the following image:

你想让它看起来像这样:

and you want to make it look like this:

(对角线末端部分根本不伸展,顶部和底部部分伸展水平,左边和右边的部分垂直伸展)

(the diagonal end pieces do not stretch at all, the top and bottom pieces stretch horizontal, and the left and right pieces stretch vertical)

要做到这一点,在iOS中使用 -stretchableImageWithLeftCapWidth:topCapHeight: 4.x及更早版本,或 -resizableImageWithCapInsets:从iOS 5开始。

To do this, use -stretchableImageWithLeftCapWidth:topCapHeight: in iOS 4.x and earlier, or -resizableImageWithCapInsets: starting with iOS 5.

UIImage *myImage = [UIImage imageNamed:@"FancyButton"];
UIImage *myResizableImage = [myImage resizableImageWithCapInsets:UIEdgeInsetsMake(21.0, 13.0, 21.0, 13.0)];
[anImageView setImage:myResizableImage]

为了帮助可视化缩放,这里有一张图片显示以上上限:

To help visualize the scaling, here is an image showing the above cap insets:

这篇关于如何在iPhone应用程序中仅缩放图像的特定部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆