开发者

get UIBarButtonItem current Image name

Is it possible to get a UIBarButtonItem's current开发者_JAVA百科 Image name?


See here.

UIBarButtonItem *item; // Assume this exists.
UIImage *image = item.image;

Edit

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.


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.


UIImageView *imageView = ((UIImageView *)(barButtonItem.customView.subviews.lastObject));
file_name = imageView.accessibilityLabel;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜