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

UIBarButtonItem shows questionmark placeholder while the button action gets performed in iOS 11

NF997 opened this issue · comments

I have multiple UIBarButtonItems like this:
let plusButton = UIBarButtonItem(title: "Plus", style: .plain, target: self, action: #selector(showMore))
plusButton.setIcon(icon: .ionicons(.iosPlusOutline), iconSize: 25.0, color: Colors.drakGreen)
Till iOS 10 everthing worked fine. But under iOS 11 I get a questionmark placeholder when I press one of the buttons. This placeholder stays there until the action the button triggers is completed:
2017-09-27 13 12 04

@NF997
I do not understand much of GIT commands, so I will not commit to the repository, If you can do that or even the creator. Thnks
Document: Source/SwiftIcons.swift

Add after line 595:
setTitleTextAttributes([NSFontAttributeName: font!], for: .highlighted)

In the extension of the UIBarButtonItem only the font is added to the normal state.
Line 595 -> setTitleTextAttributes([NSFontAttributeName: font!], for: .normal)
However, there are other states. As in the case above that solved my problem, that question mark occurred by clicking the button.
If you want to know all the states that it can behave, go to UIControlState. But I believe the above line will solve this problem.

@ranesr Would you mind merging my PR? :)

This can be fixed for Swift 4 by adding the following after line 595:

setTitleTextAttributes([NSAttributedStringKey.font: font!], for: .highlighted)
setTitleTextAttributes([NSAttributedStringKey.font: font!], for: .disabled)
setTitleTextAttributes([NSAttributedStringKey.font: font!], for: .selected)
setTitleTextAttributes([NSAttributedStringKey.font: font!], for: .focused)

@ranesr Would you please patch this when you get a chance?

Released 2.0.1 version for patching this issue.