很简单,直接上代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *myButton = [[UIButton alloc]initWithFrame:CGRectMake([[array objectAtIndex:0] floatValue], [[array objectAtIndex:1] floatValue], [[array objectAtIndex:2] floatValue], [[array objectAtIndex:3] floatValue])];
UIImage *image = [UIImage imageNamed:@"1.png"];
[myButton setBackgroundImage:image forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside ];
[self.view addSubview:myButton];
[myButton release];
}
-(void)buttonAction:(id)sender{
UIButton *button = (UIButton *)sender;
UIImage *image = [button backgroundImageForState:UIControlStateNormal];
imageView = [[UIImageView alloc]initWithFrame:self.view.frame];
imageView.image = image;
[self.view addSubview:imageView];
[button release];
[image release];
[imageView release];
}