0

I have created a UIButton programmatically in my iphone application using this code :

UIButton *button = [UIButton          buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self 
       action:@selector(aMethod:)
 forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View"  forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0,  160.0, 40.0);
[view addSubview:button];

Now what I want to do is: when I touch down this button (first action) to show a hidden label and when I release it, it takes me to another view (second action). Does any one can help me to approach that. Thanks.

4

1 回答 1

4

尝试这个

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonTouchDown:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(buttonTouchUp:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(buttonTouchUpOutside:) forControlEvents:UIControlEventTouchUpOutside];


- (void) buttonTouchDown:(id) sender
{
    //show hidden label
}

- (void) buttonTouchUp:(id) sender
{
    //hide hidden label
    //goto second view
}
- (void) buttonTouchUpOutside:(id) sender
{
    //hide hidden label
}
于 2013-02-03T03:20:53.487 回答