目的:


触摸内部时,将更改按钮背景图像


码:

- (void)addMyButton{    // Method for creating button, with background image and other properties

    UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
    [self.view addSubview:playButton];
    playButton.frame = CGRectMake(150, 150, 100, 100);
    //set title,backgroundcolor...

    UIImage *buttonImageNormal = [UIImage imageNamed:@"red.png"];
    UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:0 topCapHeight:0];
    [playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];

    if([playButton isTouchInside:[UIImage buttonImageNormal]]) //This line warning
    {
        UIImage *buttonImageNormal2 = [UIImage imageNamed:@"yellow.png"];
        UIImage *strechableButtonImageNormal2 = [buttonImageNormal2 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
        [playButton setBackgroundImage:strechableButtonImageNormal2 forState:UIControlStateNormal];

    }
}


请告诉我我目前在警告栏中所做的事情。
告诉我什么错误。
并告诉我'isTouchInside'的语法。
如果你喜欢,就做我的目标。

最佳答案

尝试更改:

if([playButton isTouchInside:[UIImage buttonImageNormal]])


至:

if([playButton isTouchInside])


isTouchInside不接受任何参数

07-26 09:38