How to get the name of the backgroundImage from a button?

后端 未结 2 1098
后悔当初
后悔当初 2020-12-21 06:56

i´ve created different buttons and initalized them with an array with photos as backgroundImage.

UIButton* myButton = [UIButton buttonWithType:UIButtonTypeRo         


        
相关标签:
2条回答
  • 2020-12-21 07:03

    The way i tried to get the UIbutton's background imageName is , set the title of UIButton same that of image name and set the hidden property of button label to YES. (I was using iCarousel)

     button.titleLabel.text=[imageArray objectAtIndex:index];
    button.titleLabel.hidden=YES;
    [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
    

    and in 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];
    

    woking fine.

    0 讨论(0)
  • 2020-12-21 07:07

    Since UIImage does not store the name of the image it contains, you can't. You have to store the name elsewhere by yourself in relationship to the Button or image.

    regards

    0 讨论(0)
提交回复
热议问题