Reputation: 28248
Is it possible to get a UIBarButtonItem's current Image name?
Upvotes: 2
Views: 1758
Reputation: 619
UIImageView *imageView = ((UIImageView *)(barButtonItem.customView.subviews.lastObject));
file_name = imageView.accessibilityLabel;
Upvotes: 0
Reputation: 16024
UIBarButtonItem *item; // Assume this exists.
UIImage *image = item.image;
Okay. I've reread your question. If you create an image with the +[NSImage imageNamed:]
method, the name is only used to find the original file. After that, only the image data is stored. Therefore, it isn't possible to recapture the name of the image. An alternative to this is to create subclass UIBarButtonItem
and include an NSString *name
property. You would initialize this bar item with an image name, it would store the data like its super does, and it would also store the image name. I hope this solves your problem.
Upvotes: 3
Reputation: 16709
It is not possible, since UIBarButtonItem gets UIImage instance as parameter so it doesn't know anything about the source of the image (it is logical because an image could be not from file). However you can subclass the UIBarButtonItem and add additional property like imageSource.
Upvotes: 1