当使用resizableImageWithCapInsets:为UIButton创建图像时,只有正常状态(使用setBackgroundImage:forState :)设置图像的状态才有效.所有其他状态显示间隙而不是绘制的图像.UIButton表示,如果没有为特定状态设置图像,则正常状态图像将与覆盖一起用于禁用和选定状态.
这是正常状态:
这是选定的州:
这是源图像:
它显然是使用我提供的可调整大小的图像,但图像没有绘制调整大小的区域.(您可以看到左右边缘,但是不会绘制刚刚拉伸的中间区域).
有趣的是,stretchableImageWithLeftCapWidth:topCapHeight:确实有效.现在这是iOS 5中不推荐使用的方法,但是由于新API中显示了差距,我可能会被困在使用它.
我确实认识到我可以为每个州提供更多的图像,但是这会破坏我正在努力减少内存占用的目的,并且增加了对我想要避免的图形设计器的额外依赖性.
// This is the gist of the code being used
UIImage* image = [UIImage imageNamed:@"button.png"];
UIEdgeInsets insets = UIEdgeInsetsMake(image.size.height/2, image.size.width/2, image.size.height/2, image.size.width/2);
image = [image resizableImageWithCapInsets:insets];
[self.button setBackgroundImage:image forState:UIControlStateNormal];
// Even doing the following results in the same behaviour
[self.button setBackgroundImage:image forState:UIControlStateSelected];
Run Code Online (Sandbox Code Playgroud) 我已经能够在所有其他视图(包括键盘)上方放置半透明视图,以使用以下代码对屏幕进行着色:
int count = [[[UIApplication sharedApplication]windows]count];
[[[UIApplication sharedApplication] windows] objectAtIndex:count-1]addSubview:tintView];
Run Code Online (Sandbox Code Playgroud)
现在我遇到了一个问题.我的应用程序使用MessageUI.framework来显示MFMessageComposeViewController,它允许用户发送文本消息.这是我遇到问题的地方.
当我在这种情况下执行上面的代码时(显示消息视图时),它可以正常工作.问题是,用户无法再与其下方的消息视图进行交互.我一直在我的tintView上将userinteractionenabled设置为NO,但在这种情况下它没有帮助解决问题.
但是,将隐藏的色调视图设置为YES确实允许交互.通过更改此属性可以使消息视图与之交互.显然,我希望tintView可见.
我在最顶层的UIWindow中查看了视图,发现UIRemoteView(我找不到任何信息,但似乎是在MessageUI.framework中显示的视图)是当tintView在它上面时没有接收到触摸的视图.
即使在其上显示另一个UIView,我如何允许与MFMessageComposeViewController进行交互.Userinteractionenabled在这种情况下不起作用,但将视图设置为隐藏(这不是我想要的).