Skip to content
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

Single line label will not full justify #44

Open
cmdahler opened this issue Oct 5, 2011 · 4 comments
Open

Single line label will not full justify #44

cmdahler opened this issue Oct 5, 2011 · 4 comments

Comments

@cmdahler
Copy link

cmdahler commented Oct 5, 2011

When creating a simple single line label, the text within it will not fully justify. The text of the label is justified just like any single-line paragraph or the last line of a paragraph: it is left justified rather than having a line run that is significantly shorter than the frame extend out with a lot of spaces between the words and letters. Doing full justify on a single line of text or the last line of a paragraph is called force-justify.

I am trying to set up a single-line label using OHAttributedLabel, but even with the alignment property set to UITextAlignmentJustify, it remains left-justified because it is a single line of text. Is there a way to force-justify a single line label? Even if the text in the label is significantly shorter than the width of the label, in this case I actually want the text to expand with spaces between the words and so on so that the first letter in the label is on the left margin and the last character is on the right margin.

@AliSoftware
Copy link
Owner

Hi Chris

I've seen your question but I don't think CoreText enables this behavior. In any text layout system (word processor, etc) as well as in CoreText, text justification applies on multiline paragraphs and never on the last line. In case you only have one line, it won't be justified.

I'm not sure there is an option in CoreText (thus in OHAttributedLabel) to override this behavior. If there is anyway, it would be in the NSAttributedString attributes to apply on your string. Check on the CoreText String Attributes Reference and maybe the CTParagraphStyle attribute?

Sorry I won't have much time those days to look at this, really busy. let me know if you find something useful in CoreText doc to implement this unusual behavior of text justification.

@cmdahler
Copy link
Author

cmdahler commented Oct 5, 2011

I will investigate it and post any results I find. Actually, most word processors do have a way to do this, it's usually called force-justify. After looking around a little bit in Core Text, I believe there is a way to do this, but it involves setting the text up line-by-line rather than a single framesetter. I have a total of about 3 hours of Core Text experience at this point, but if I educate myself enough on this subject, I'll post the results.

@AliSoftware
Copy link
Owner

Yup, I think some day I'll need to switch the OHAttributedLabel code so it uses its own framing procedure instead of using a CTFrameSetter, because it will probably allow me to force-justify as you wish, but also manage text truncation (Issue #3).

The problem is that our own framing mechanism for the whole OHAttributedLabel code will need some work, especially check that the link detection system still works right and detect links at the right position, and the centerVertically property is still taken into account to, etc... So it has to be done right and won't have time to spend on this and check all the use cases myself until... probably next year :(

So if you investigate on implementing even the premicises of manual layout of the CTLines of the text (for the multiline cases too -- even if you only need single line for your code we need this to work for everyone), even if it not a final implementation it will be greatly appreciated and save some time ;)

Thanks

@takasurazeem
Copy link

BUMP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants