5

如何在点击时显示 UIButton 的选定状态?

我想要它,这样当人们点击 uibutton 时,它会通过我的悬停显示选定状态?

现在他们必须按住按钮才能看到悬停。

[t1 setBackgroundImage: [UIImage imageNamed: [NSString stringWithFormat: @"hover.png"]] forState:UIControlStateSelected];

我也想在点击时显示悬停图像。

4

2 回答 2

0

您需要为按钮设置选中状态

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setImage:[UIImage imageNamed:@"hover.png"] forState:UIControlStateSelected];

要在按下按钮时显示 hoover 图像,您需要将 state 属性设置为UIControlStateHighlighted

于 2013-01-21T18:46:05.333 回答
0

我遇到了同样的问题-我的按钮在按下(点击+按住)时突出显示,而在简单点击时却没有。这是我的代码:

btn = [UIButton buttonWithType:UIButtonTypeCustom];
        UIImage *image =[UIImage imageNamed:@"btn"];
        UIImage *imageSelected =[UIImage imageNamed:@"btn_tap"];
        [btn setBackgroundImage:transImage forState:UIControlStateNormal];
        [btn setBackgroundImage:imageSelected forState:UIControlStateHighlighted];
    [btn addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];

-(void)btnPressedWithDelay{
    //your code for btn action
}

- (void) action:(UIButton *)sender{
    [self performSelector:@selector(btnPressedWithDelay) withObject:nil afterDelay:0.1];
}

它对你有用吗?

于 2013-04-26T19:56:22.883 回答