我已经创建了不同的按钮,并使用带有照片作为backgroundImage的数组进行了初始化.
UIButton* myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[myButton setBackgroundImage:[UIImage imageNamed: (NSString*) obj ] forState:UIControlStateNormal];
[myButton addTarget:nil action:@selector(buttonDown: ) forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
这是我的buttonDown方法:
-(void) buttonDown:(UIButton*) sender {
NSLog(@"pressed: %@", sender.currentBackgroundImage );}
Run Code Online (Sandbox Code Playgroud)
这跟我说:"按下:<UIImage:0x6625c40>"
现在我想知道如何获得任何点击按钮的图像名称?很高兴知道.谢谢你的时间.
路上我试图让 UIbutton的背景imageName是,设置title的UIButton相同的形象的名称和设置hidden property的button label到YES.(我在用iCarousel)
button.titleLabel.text=[imageArray objectAtIndex:index];
button.titleLabel.hidden=YES;
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
在buttonTapped,
UIButton *button=(UIButton*)sender;
NSLog(@"The button title is %@",sender.titleLabel.text);
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Button Tapped Is" message:sender.titleLabel.text delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];
//[alert show];
Run Code Online (Sandbox Code Playgroud)
好好的.