hi I would like to ask how I can set the image of the various button2 created from users on my uiview . please help me!!
Code:
Code:
- (void)CREATEBUTTON:(id)sender {
i++;
UIButton *button2 =[[UIButton alloc] initWithFrame:CGRectMake(100, 80, 55 , 55)];
NSString* buttonTitle = [NSString stringWithFormat:@"Button%d", i];
[button2 setTitle:buttonTitle forState:UIControlStateNormal];
NSString *selectorName = [NSString stringWithFormat:@"SwitchButton%d:", i];
[button2 addTarget:self action:NSSelectorFromString(selectorName) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[button2 setBackgroundImage:[UIImage imageNamed:@"OFF.png"]
forState:UIControlStateNormal];
[button2 setBackgroundImage:[UIImage imageNamed:@"ON.png"] forState:UIControlStateSelected];
buttonToggle = NO;
[self.view addSubview:button2];
}
- (void)SwitchButton1:(UIButton*)sender
{
buttonToggle = !buttonToggle;
if (buttonToggle == YES)
{
NSLog(@"1ON");
}
else
{
NSLog(@"1OFF");
}
}
- (void)SwitchButton2:(UIButton*)sender
{
buttonToggle = !buttonToggle;
if (buttonToggle == YES)
{
NSLog(@"2ON");
}
else
{
NSLog(@"2OFF");
}
}