ios - Convert a string to show an image of the same name using UIImageView -
i have plist questions, answers , card names(eg as, 2c etc) strings.
i use text in string eg (ace of spades) , show image of as.png in uiimageview (or method really)
my code pull current string is;
boardcard1.text = currentquestion.boardcard1 boardcard2.text = currentquestion.boardcard2
this pulls card names string fine, how can convert image filename , have image display?
thank in advance can provide.
edit:
the images saved in folder in app - resources\images\4 color deck cards\
plist looks :
<dict> <key>scenario</key> <string>some scenario text</string> <key>boardcard1</key> <string>6d</string> <key>boardcard2</key> <string>5c</string> <key>boardcard3</key> <string>4c</string> <key>explanation</key> <string>some explanation text</string> <key>answers</key> <array> <string>64</string> <string>65, 64 & 54</string> <string>54</string> <string>65 & 54</string> <string>65</string> <string>65 & 64</string> </array> <key>correctanswer</key> <string>65</string> <key>question</key> <string>some question text</string> </dict>
you can use string interpolation include current value of variable in string. can use uiimage(named:)
initialize uiimage
image stored in assets catalogue or part of project.
let image = uiimage(named: "\(currentquestion.boardcard1)")
Comments
Post a Comment