Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Justified Alignment in UITextView - iPhone

Tags:

In my application, i have a UITextView with many lines, but I need the data with proper appearance.

Is it possible to have Justified Alignment in UITextView?

like image 717
Sagar Kothari Avatar asked Aug 19 '09 17:08

Sagar Kothari


People also ask

What is the justified alignment option?

When you justify text, space is added between words so that both edges of each line are aligned with both margins. The last line in the paragraph is aligned left. Click anywhere in the paragraph that you want to justify. On the Home tab, in the Paragraph group, click Justify Text .


3 Answers

I know it's an old question but now we have news about :

UITextView *textView = // init your text view textView.textAlignment = NSTextAlignmentJustified; 

And that's it !

UPDATE: This only works on iOS 6 and above

like image 164
fencingCode Avatar answered Oct 19 '22 18:10

fencingCode


I have come to a solution that works. First of all, you will need to change your UITextView and use a UIWebView instead.

Details.h

@interface Details : UIViewController {
    IBOutlet UIWebView *descripcion;
}

@property (nonatomic, retain) UIWebView *descripcion;

Then, load your UIWebView as follows:

Details.m

[descripcion loadHTMLString:[NSString stringWithFormat:@"<div align='justify'>%@<div>",YOUR_TEXT] baseURL:nil];
like image 43
Roger Avatar answered Oct 19 '22 20:10

Roger


There is solution:

NSString *text1 = @"Sample text : A his is my weblog in English, German and Korean. If you want to know more about a pizza stone once it’s cooled down.";

NSMutableParagraphStyle *style =  [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[style setAlignment: kCTJustifiedTextAlignment];

NSAttributedString * subText1 = [[NSAttributedString alloc] initWithString:text1 attributes:@{
                                                NSParagraphStyleAttributeName : style
                                     }];

_myUiTextView.attributedText = subText1;
like image 44
Andro Avatar answered Oct 19 '22 19:10

Andro