iOS Swift Add SVG Image to button like Android -
in android, can import svg vector xml, use drawable, change colors of svg icons , add button
void setsvgicnforbtnfnc(button setbtnvar, int setsvgvar, int setclrvar, string posvar) { drawable devdmjvar = getdrawable(setsvgvar); devdmjvar.setbounds(0,0,dpx24,dpx24); devdmjvar.setcolorfilter(new porterduffcolorfilter(setclrvar, porterduff.mode.src_in)); switch (posvar) { case "tit" : setbtnvar.setcompounddrawables(null, devdmjvar, null, null); break; case "rit" : setbtnvar.setcompounddrawables(null, null, devdmjvar, null); break; case "pit" : setbtnvar.setcompounddrawables(null, null, null, devdmjvar); break; default: setbtnvar.setcompounddrawables(devdmjvar, null, null, null); break; } } how do in swift iphones ?
setbtnvar.setimage(<image: uiimage?>, forstate: <uicontrolstate>)
upd: see useyourloaf blog post
just found on erica sadun blog post on ios 11 could use vector assets.
what "vector assets" mean:
if click box, vector data shipped application. which, on 1 hand, makes application little bit larger, because vector data takes space. on other hand, give opportunity scale these images, might useful in number of different situations. so, 1 is, if know particular image going used @ multiple sizes. might less obvious. so, 1 case symbolic glyph should resize dynamic type. since we're thinking dynamic type, should thinking having glyphs appearing next type resize appropriately. case that's not obvious, tab bar images. ... there's great accessibility feature recommend supporting, allows user have turned dynamic type size up. ... so, recommend doing increase usability of app across users
how use:
- convert svg file pdf, e.g. on zamzar.com
- add pdf
assets.xcassets- click "preserve vector data" imported pdf.
- create
uiimageviewinuiviewcontroller, assign pdf fileuiimage.
ios < 11
there no native way use svg image.
take @ macaw
import framework via cocoapod
pod "macaw", "0.8.2" check example project: how render tiger.svg (located in project directory, not in assets.xcassets file)
import uikit import macaw class svgexampleview: macawview { required init?(coder adecoder: nscoder) { super.init(node: svgparser.parse(path: "tiger"), coder: adecoder) } } there other third-party libraries of course:
Comments
Post a Comment