图像未使用resizableImageWithCapInsets正确调整大小 [英] Image not resizing correctly using resizableImageWithCapInsets

查看:128
本文介绍了图像未使用resizableImageWithCapInsets正确调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用/理解 resizableImageWithCapInsets

我已按如下方式设置按钮:

I have setup a button as follows:

facebookLoginButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 20, 300,50)];
facebookLoginButton.autoresizingMask = UIViewAutoresizingFlexibleWidth;

UIImage *facebookButton = [[UIImage imageNamed:@"FacebookLogin"]
                           resizableImageWithCapInsets:UIEdgeInsetsMake(20,90,20,56)];
[facebookLoginButton setBackgroundImage:facebookButton forState:UIControlStateNormal];

[facebookLoginButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[facebookLoginButton setTitle:NSLocalizedString(@"FacebookLoginButton", "Facebook Login Button") forState:UIControlStateNormal];
[facebookLoginButton setTitleShadowColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.35] forState:UIControlStateNormal];
[facebookLoginButton addTarget:self action:@selector(facebookLoginButton:) forControlEvents:UIControlEventTouchUpInside];

如上所示,按钮视图的框架为300x50像素。我为视网膜创建了一个图像(然后将缩小)。

As you can see above the frame for the button view is 300x50 pixels. I have created an image for retina (then will scale down later).

图像是在PS中创建的png,大小为144x100px。这是帧的高度(对于uibutton)的两倍以及具有Facebook F的空间所需的宽度。我们的想法是让F保持静态在左侧和可伸展部分,如下所示。

The image is a png created in PS, sized 144x100px. That is double the height of the frame (for uibutton) and the width necessary to have the Facebook F, with space. The idea is to have the F stay static on the left and the stretchable part as highlighted below.

如果有帮助,这是图像本身;

Here is the image itself if that helps;

此处是目前的结果:

我试图找出要输入的正确插图。我已经搜索了大量的教程,但没有一个解释得足以让我理解插图实际上是如何工作的。如果有人可以解释这个或链接到一个教程,如何计算它们会更好。

I am trying to find out the correct insets to enter. I have searched through a load of tutorials on this but none have explained enough for me to understand how the insets actually work. If anyone could explain this or link to a tutorial on how they are calculated that would be even better.

我目前将顶部和底部设置为0理论上他们不需要重复,只需要一个大于静态右边的静态。右侧的插图仅用于圆形边框,中间部分需要重复。

I have currently set the top and bottom as 0 as in theory they do not need repeating, just a static left larger than the static right. The inset for the right is only for the rounded borders and the middle part needs repeating.

推荐答案

如果您使用图像进行视网膜制作确保你带有 @ 2x 的后缀名称。

还要注意你需要以单位(而不是像素)来指定意图。

If you using image for retina make sure that you postfixed name with @2x.
Also make note that you need to specify intents in units (not pixels).

UIImage *facebookButton = [[UIImage imageNamed:@"FacebookLogin"]
                         resizableImageWithCapInsets:UIEdgeInsetsMake(0,40,0,10)];

这篇关于图像未使用resizableImageWithCapInsets正确调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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