-
Notifications
You must be signed in to change notification settings - Fork 686
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
Vertical align not correct after setting textAligment #24
Comments
Hi @poolqf. Thanks for your issue. Please go ahead and open a PR 👍 |
Did you manage to fix this issue about the alignment? |
Nope @xScylez , the only thing I fixed was horizontal alignment, but not the vertical one. But a workaround could be to use the horizontal alignment fix, and then make the UILabel height fit to size, and then manually center the label inside the view you want |
@poolqf Could you post an example code for your workaround please? I don't fully understand what you mean. |
@xScylez taking #31 , that is fixing the horizontal alignment, the workaround for fixing de vertical alignment, in a really verbose way, could be something like this: let containerView = UIView()
containerView.frame = CGRect(x: 0, y: 0, width: 150, height: 50)
let label = ActiveLabel()
label.text = "My Text"
label.textAlignment = .Center
label.sizeToFit()
let containerHeight = containerView.frame.height
label.frame = CGRect(x: 0, y: containerHeight/2 - label.frame.height/2, width: containerView.frame.width, height: label.frame.height)
containerView.addSubview(label) It is just vertically centering the label inside the container view |
@poolqf What about if the label is already declared as a ActiveLabel in Storyboard? I can access the label using the command |
@xScylez using Storyboards it should be even easier if you play with the correct constraints |
Hi,
I am using ActiveLabel in my app, and there's a case where I need the text to be horizontal and vertical aligned. But setting the
textAlignment
property does not change anything.I added a line on the
addLineBreak(attrString:)
method expecting it to center the text as expected, but the result is the following:Correct center alignment, but incorrect vertical one.
A solution to accomplish the center alignment would be to add a
didSet
on it, as on the other variables.As for the vertical alignment, I tried a lot of things to accomplish it, but without luck, so I have no clues...
PS. I have an extension of ActiveLabel that uses a delegate instead of having to set block for each Label you create to handle user touches. Do you want me to create a PR with it?
The text was updated successfully, but these errors were encountered: