-
Notifications
You must be signed in to change notification settings - Fork 108
BadgeView does not seem to resize depending on content #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello @camdata, the badge should resize to according the size of the text. If it doesn't then there must be a bug. Can you tell me about your issue? |
Hi Evgenii,
thanks for your reply. First i do like your framework and i implemented the following work around:
func setBadge(count: Int) {
badgeView.text = String(count)
badgeView.alpha = count == 0 ? 0 : 1
badgeView.bounds.size.width = 10 + badgeView.text!.widthOfString(usingFont: badgeView.font)
}
using:
func widthOfString(usingFont font: UIFont) -> CGFloat {
let fontAttributes = [NSAttributedStringKey.font: font]
let size = self.size(withAttributes: fontAttributes)
return size.width
}
Hope that helps,
Mike
… Am 20.11.2017 um 22:31 schrieb Evgenii Neumerzhitckii ***@***.***>:
Hello @camdata <https://github.com/camdata>, the badge should resize to according the size of the text. If it doesn't then there must be a bug. Can you tell me about your issue?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#17 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AfUtkHQn2t2TnVYkwY-sugTuJ91AnD9gks5s4e-mgaJpZM4QkpBB>.
|
Thanks for the workaround. I would like to know why the badge does not resize in the first place. As you probably noticed, the badge is just a UILabel. Therefore, it should resize itself automatically. It should not require setting its size explicitly. Can you describe your use case, so we can fix the problem?
|
UILables do only autoresize if line number are set to zero (from iOS 6+ on) - maybe thats the point? You could also use the sizeToFit method internally inside badgeView. The is no UIinspactable i could find regarding the line number. Mayber i am doing something else wrong.
I used Storyboard to place a badgeView inside of a VC. The method i sent you is the only place where i update the badgeView. I do not redraw the badgeView manually somewhere.
… Am 21.11.2017 um 12:13 schrieb Evgenii Neumerzhitckii ***@***.***>:
Thanks for the workaround. I would like to know why the badge does not resize in the first place. As you probably noticed, the badge is just a UILabel. Therefore, it should resize itself automatically. It should not require setting its size explicitly.
Can you describe your use case, so we can fix the problem?
How do you use and position the badge?
When do you update it?
Do update the badge from the main queue?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#17 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AfUtkGeMyT9E7xVCmQws642X_Nb5HTcFks5s4rBigaJpZM4QkpBB>.
|
I could not reproduce your problem. I've made a demo app with a badge and a stepper that changes the number. The badge autoresize automatically, when "Lines" property is 1 (which is default) and 0. Do you update the badge number in the main queue? Please find the demo attached. |
You can also use |
Xcode 9.1 /Swift 4
Is it intendet that the badgeView does not resize dynamically regarding its content?
I would expect a widget to do that
The text was updated successfully, but these errors were encountered: