2

I've created one button like this:

close=[[UIButton alloc]init];
    close.frame=CGRectMake(285, 0, 35, 50);
    [self.view addSubview:close];
    [close setBackgroundImage:[UIImage imageNamed:@"close2.jpg"] forState:UIControlStateNormal];
    [close addTarget:self action:@selector(aclose:) forControlEvents:UIControlEventTouchDown];

and I have one NSString. When I click on the button, I need to pass the image name to NSString. Is that possible?

alexwlchan
  • 5,699
  • 7
  • 38
  • 49
ios start
  • 65
  • 8
  • try this i think it will help you http://stackoverflow.com/a/5500525/2518805 @ios start – sanjeet Aug 27 '14 at 04:37
  • Yes to solve this you should make a custom class of UIButton, make a property in this custom class named imgName and use this class in place of UIButton – Yogendra Aug 27 '14 at 04:41
  • 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. – Soumya Ranjan Aug 27 '14 at 05:06

1 Answers1

0

It is not possible to get image name from a button as UIImage does not store the name of the image it contains. You have to store image name elsewhere by yourself. Method of storing image name depends on what you want to accomplish with the name of the image.

Viper
  • 1,408
  • 9
  • 13