2

I have seen questions posted on here asking how to left and right align two lumps of text, but how can I neatly left and right justify an entire paragraph inside a multiline cell? (Such as what MS Word etc would do if you click on the justification button so that left and right sides of the text are always aligned).

SparkyNZ
  • 6,266
  • 7
  • 39
  • 80

2 Answers2

2

You can also create a custom cell with label which IBOutlet to this class that can be downloaded on github OHAttributedLabel, then try the code below

cell.label.textAlignment = UITextAlignmentJustify;
DLende
  • 5,162
  • 1
  • 17
  • 25
  • Thankyou dianz - I will give that a go when I can. I'm new to Mac/iPhone programming so I'm a little bit on the slow side when it comes to anything involving IB and IBOutlets. – SparkyNZ Jun 17 '12 at 05:05
  • Well I have just downloaded and built the example. After changing the text in the label I see that the label justification does exactly what I want.. The only thing I'm not so sure about is how this will work with a UITextField (this is what I've changed my application to use so that I can edit the cell content using the pop-up touch keyboard. Sorry.. when I posted my question lastnight I had absolutely no idea how to edit text at all - still on the steep learning curve. – SparkyNZ Jun 17 '12 at 05:12
1

Is this what you're looking for?

yourTextLabel.textAlignment = UITextAlignmentCenter;

Along with the frame size that you want for your text label.

Neeku
  • 3,646
  • 8
  • 33
  • 43
  • No, I'm afraid not - that will centre each line leaving the left and right edges of the text all wavey. I'd like the text on both left and right sides to flow straight down. Thanks. – SparkyNZ Jun 16 '12 at 05:54
  • I see. Have you tried these possible solutions? 1. [CATextLayer](http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CATextLayer_class/Introduction/Introduction.html) 2. http://stackoverflow.com/questions/3968426/how-to-justified-the-text-in-uitextview 3. http://stackoverflow.com/questions/2544905/how-to-change-an-uilabel-uifonts-letter-spacing 4. http://stackoverflow.com/questions/402339/getting-justified-text-in-uitextfield – Neeku Jun 16 '12 at 06:00