Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

iphone - Adding Images to UIActionSheet buttons as in UIDocumentInteractionController

Is it possible to add an image to the buttons of the UIActionSheet as seen in UIDocumentInteractionController? If so, please let me know how it is done.

image

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is a possibility to add images (to be exact: icons or symbols) to the buttons of a UIActionSheet (or a UIAlertView) without loading image files or fiddling around with (sub)views. In these classes buttons are specified by their titles, which are strings. So it is obvious to use symbols, which one can specify also by strings. The first I came up with was using unicode symbols.

Then I discovered that several of them are rendered as nice icons on iOS and as one can see for several symbols in the Character Viewer on Mac OS, too. Thus, the symbols can be used actually everywhere a string can be specified.

The drawbacks of this approach are:

  • You are limited to predefined symbols.
  • Not all symbols are rendered as they should (e.g. u29C9).
  • There can be changes in the appearance of some symbols on different iOS versions (e.g. U0001F533 on iOS 5 and 6).

Here are some interesting symbols among others:

If you want to quickly check how a symbol looks like (at least on Mac OS), you can use the Calculator. Check definitely in the simulator: For instance u2B1C is not an icon in Calculator 10.7.1.

Screenshots:

UIActionSheet

UIActionSheet

Button titles:

@"U0001F6A9 U0001F4CC u26F3 u2690 u2691 u274F u25A4 Test"
@"U0001F4D6 U0001F30E U0001F30F u25A6 U0001F3C1 U0001F332 U0001F333 U0001F334 Test"

UIAlertView

enter image description here

Button title:

@"u26A0 Yes"

UITableViewCell with checkbox and other icons

UITableViewCell


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...