简体   繁体   English

显示自定义UIButton上的灰色叠加

[英]Gray Overlay on a custom UIButton getting displayed

I have created a custom UIButton for an iOS 4.3+ application . 我为iOS 4.3+应用程序创建了一个自定义UIButton I wanted to make the background image stretch, so I and used the following methods to set its background image: 我想拉伸背景图像,所以我使用以下方法设置背景图像:

[myButton setBackgroundImage:[[UIImage imageNamed:myImagePath]  stretchableImageWithLeftCapWidth:leftStretchValue topCapHeight:topStretchValue] forState:UIControlStateNormal]
[myButton setBackgroundImage:[[UIImage imageNamed:myHighlightedImagePath]  stretchableImageWithLeftCapWidth:eftStretchValue topCapHeight:topStretchValue] forState:UIControlStateHighlighted]
[myButton setBackgroundImage:[[UIImage imageNamed:mySelectedImagePath]
stretchableImageWithLeftCapWidth:eftStretchValue topCapHeight:topStretchValue] forState:UIControlStateSelected]

I have added an event handler to the custom button 我已将事件处理程序添加到自定义按钮

[myButton addTarget:self action:@selector(buttonHighlighted:) forControlEvents:UIControlEventTouchDown];

[myButton addTarget:self action:@selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside];

In the above mentioned methods, I have set the selected and the highlighted state of the button accordingly. 在上述方法中,我已经相应地设置了按钮的选定状态和突出显示状态。 I have changed the frame of the UIButton to adjust the dimensions of an irregular image (mySelectedImage and myHighlightedImage, neither of which is a rectangle) , so that it gets aligned properly along with myImage. 我更改了UIButton的框架以调整不规则图像的尺寸(mySelectedImage和myHighlightedImage,都不是矩形) ,以便它与myImage正确对齐。

- (void) buttonSelected {
myButton.selected = !myButton.selected; //setting the selected property to NO in the     viewDidLoad

//code to change the frame of the UIButton to accomodate the irregular image
}


- (void) buttonHighlighted {
myButton.highlighted = YES;
}

The problem I am facing is that when I select myButton, a gray color overlay is displayed on myImage for a very short time before the images myHighlightedImage and mySelectedImage are displayed as its background. 我面临的问题是,当我选择myButton时,在myImage上显示灰色的覆盖层很短的时间,然后图像myHighlightedImage和mySelectedImage被显示为其背景。 I have set the background color of myButton as clearColor , thinking that might be the reason, but it is not getting solved. 我已将myButton背景色设置为clearColor ,以为可能是原因,但尚未解决。

What could be the possible issue... ? 可能是什么问题...?

button.adjustsImageWhenHighlighted = NO;

我认为这就是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM