ranesr / SwiftIcons

🎢Swift Library for Font Icons - ★ this library

Home Page:https://ranesr.github.io/SwiftIcons/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how can i change the post text without changing the icon

opened this issue · comments

i have a button but i want to change the post text only not the button how can i complete that

Can you explain it more? I did not understand what you meant.

I have a uibutton pretext with an icon that will need to constantly be update now when this this update i dont want the icon to be update because this will remove the view and renter the view into the view again.

this is what im using right now
myButton.setIcon(prefixText: "", icon: .googleMaterialDesign(.print), postfixText: " 66", forState: .normal)

i want to update by doing this
myButton.postfixText = "my postfix text here "

If you look at the source you'll see that the prefix, postfix and icon are all concatenated together with the various attributed string attributes for each.

https://github.com/ranesr/SwiftIcons/blob/master/Source/SwiftIcons.swift#L321

So there is currently no way of changing just one of the 3 components, as the "settings" are not stored anywhere.

The simplest solution would be to create a custom UIButton, that has the 3 component parts (maybe have a "text" and "attributes dictionary" for each part. Then use the didSet closure to re-run the setIcon function, whenever any of those properties change.

@ranesr seems to have taken the simplest approach to integrate the icon's, which I prefer over bloated libraries with 100's of components to support all the various possibilities. So i'm not too sure whether such components would be a welcome addition to this library, or if it would better too "roll your own" library based on this one. Maybe ranesr can make his vision known for this library, so we know whether contributing back custom components is worthwhile, or if he prefer's too keep things simple.