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

后端 未结 2 1167
后悔当初
后悔当初 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.

提交回复
热议问题