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
Invalid line spacing for last line with button #9
Comments
I found that when there are two different font sizes in a row, it will look like in the screenshot. This is a problem of NSAttributedString, but I know how to achieve the desired effect. Can be solved by setting the line height:
e.g. |
The root cause is the difference between line spacing and line height. |
I try set -2, and it no do anything for me. If positive - doing |
Is the line height invalid? |
I set only |
After running this code, what is the result? |
God, can you extract more complete code for me, I need to debug and analyze. |
Before that, I need to confirm whether the system font is used? |
Sorry, I simple use your code as you send. let textFont = UIFont.preferredFont(forTextStyle: .footnote)
let buttonFont = UIFont.preferredFont(forTextStyle: .footnote, weight: .medium)
let textAttributed = AttributedString(NSAttributedString(string: text + text), .font(textFont), .foreground(descriptionLabel.textColor))
let buttonAttributed = AttributedString(NSAttributedString(string: button), .font(buttonFont), .foreground(buttonColor), .action([.foreground(buttonColor.withAlphaComponent(0.5))], action))
descriptionLabel.attributed.text = .init(textAttributed + " " + buttonAttributed, .paragraph(.maximumLineHeight(-2), .minimumLineHeight(-2))) |
|
Line height must be greater than 0 to take effect |
@lixiang1994 you full right. I set zero and it not work. When I set |
Line spacing and line height are different. |
My pleasure |
Sorry, catch strange behaviour. Code let textFont = UIFont.preferredFont(forTextStyle: .footnote)
let buttonFont = UIFont.preferredFont(forTextStyle: .footnote, weight: .medium).rounded()
let buttonColor = SPInterface.tintColor
let text = "you full right. I set zero and it not work. When I set textFont.lineHeight it start work. Thanks for your time and big help!"
let button = "Action"
let textAttributed = AttributedString(NSAttributedString(string: text), .font(textFont), .foreground(descriptionLabel.textColor))
let buttonAttributed = AttributedString(NSAttributedString(string: button), .font(buttonFont), .foreground(buttonColor), .action([.foreground(buttonColor.withAlphaComponent(0.5))], {
print("call")
}))
descriptionLabel.numberOfLines = 0
descriptionLabel.attributed.text = .init(textAttributed + " " + buttonAttributed, .paragraph(.maximumLineHeight(textFont.lineHeight), .minimumLineHeight(textFont.lineHeight)))
scrollView.addSubview(descriptionLabel)
descriptionLabel.frame = CGRect.init(x: 20, y: 20, width: 200, height: 0)
descriptionLabel.sizeToFit() It basic code, only with line height. |
Try it.
|
|
Yes, in example. I try remove it and place to view. Similar bug |
Even adding to empty project, also not work. I did example, you can check? |
Thanks. |
It work now! |
Attached example:
Code for init:
Code for layout
Number of lines set to zero.
The text was updated successfully, but these errors were encountered: