我需要翻转和图像,然后将其添加到按钮。我使用了以下代码
UIButton *playButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
playButton.frame = CGRectMake(xing, ying, dx,dy);
[playButton setTitle:text forState:UIControlStateNormal];
[playButton addTarget:self action:function forControlEvents:UIControlEventTouchUpInside];
UIImage *buttonImageNormal = [UIImage imageNamed:@"Begin-Set-Button.png"];
UIImage * other = [UIImage imageWithCGImage:buttonImageNormal.CGImage
scale:1.0 orientation: UIImageOrientationUpMirrored];
UIImage * awesome = [other stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[playButton setBackgroundImage:awesome forState:UIControlStateNormal];
它正确显示图像,但是当我单击它时,按钮显示未翻转的图像。
在我尝试解决这个问题时,我添加了以下代码行
[playButton setBackgroundImage:awesome forState:UIControlStateHighlighted];
然而,当我单击按钮时,它不会像使用未翻转图像创建的按钮那样使颜色变暗。
如何对其进行编码,以便当我使用翻转的图像时,它显示翻转的图像在按下时变暗?我知道如何手动使图像变暗,但我想知道是否有一种方法可以通过简单的函数调用自动完成?