【发布时间】:2012-10-11 14:06:59
【问题描述】:
我为 iOS 4.3+ 应用程序创建了一个自定义 UIButton。我想让背景图片拉伸,所以我使用了以下方法来设置它的背景图片:
[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]
我已经为自定义按钮添加了一个事件处理程序
[myButton addTarget:self action:@selector(buttonHighlighted:) forControlEvents:UIControlEventTouchDown];
[myButton addTarget:self action:@selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside];
在上面提到的方法中,我已经相应地设置了按钮的选中状态和高亮状态。我更改了 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;
}
我面临的问题是,当我选择 myButton 时,在 myHighlightedImage 和 mySelectedImage 图像显示为其背景之前,myImage 上会在很短的时间内显示灰色叠加层。我已将 myButton 的 背景颜色设置为 clearColor,认为这可能是原因,但没有得到解决。
可能的问题是什么...?
【问题讨论】:
标签: iphone objective-c ios uibutton uiimage