iphone Programming - UIButton Action
_________________________________________________________________
UIButton *myButton= [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
myButton.frame = CGRectMake(105,180, 115, 35);
[myButton setTitle:@"Apply Image" forState:UIControlStateNormal];
myButton.backgroundColor = [UIColor clearColor];
[myButton addTarget:self action:@selector(ApplyImage: )forControlEvents:UIControlEventTouchUpInside];
-(void)ApplyImage:(id)sender
{
UIView *mview= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(105,180,250,25)];
name.text = @”Button Clicked !…..”;
name.textColor=[UIColor whiteColor];
name.font=[UIFont boldSystemFontOfSize:13];
name.backgroundColor=[UIColor clearColor];
[mview addSubview:name];
[name release];
[window addSubview:mview];
[mview release];
}
_________________________________________________________________
The pink color line is main to perform the button action.
action:@selector(ApplyImage: ) –>Calling method name
addTarget:self—> the calling method is in the same class
Means we are calling ApplyImage() method on button click , which the method in the same class.