开发者

To change the state of button highlighted from normal and keeping it hold

I am creating an iphone app where I have used 25 buttons and each button 开发者_开发百科has been shown a background image in its normal mode.I have also set another image on the highlighted mode of the button.

Initially button will be shown in its normal mode now I want that when a button is pressed then button should change to its highlighted state so as the other image will be displayed there. I have done so by doing:

button.highlighted = YES;

Its working but its sets the highlighted image for a fraction and then again normal state of the button come back. I use the following code to create the buttons.

for (int i=0; i<25; i++) {

    if (i > 0) { 

        if (i%5 == 0) {

            xaxis = 28;
            yaxis = yaxis+42;
        }
    } 

    iconButton[i] = [UIButton buttonWithType:UIButtonTypeCustom]; 
    iconButton[i].frame = CGRectMake(xaxis, yaxis, 50, 40); 
    [iconButton[i] setBackgroundImage:[iconArray objectAtIndex:random] forState:UIControlStateNormal]; 
    [iconButton[i] setBackgroundImage:[tapedIconArray objectAtIndex:random] forState:UIControlStateHighlighted];
    [iconButton[i] addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.view addSubview:iconButton[i]]; 
    xaxis = xaxis+53; 
} 

How can i hold the state of the button, I even tried with timer but app get crashed then. Please help me

Many Thanks in advance


I am not sure of this but try it by setting image for button's UIControlStateSelected i.e.

[btn setImage:[UIImage imageNamed:@"selectedImage.png"] forState:UIControlStateSelected];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜