Подтвердить что ты не робот

NSTextAlignmentJustified to UILable textAligment на iOS6 выйдет из строя

Теперь я использую Xcode4.5 и iOS6, iOS6 меняют UILable textAlignment,

label.textAlignment = NSTextAlignmentJustified;

Код будет разбит на iPhone 6.0 Simulator с ios6 SDK. но не сбой на iPhone 5.0 Simulator с iOS6 SDK.

iOS6 поддерживает NSTextAlignmentJustified, но почему сбой?

4b9b3361

Ответ 1

Изменить 1:

Используя NSAttributedString, мы можем обосновать текст.

NSMutableParagraphStyle *paragraphStyles = [[NSMutableParagraphStyle alloc] init];
paragraphStyles.alignment                = NSTextAlignmentJustified;
paragraphStyles.firstLineHeadIndent      = 0.05;    // Very IMP

NSString *stringTojustify                = @"We are what our thoughts have made us; so take care about what you think. Words are secondary. Thoughts live; they travel far.";
NSDictionary *attributes                 = @{NSParagraphStyleAttributeName: paragraphStyles};
NSAttributedString *attributedString     = [[NSAttributedString alloc] initWithString:stringTojustify attributes:attributes];

self.lblQuote.attributedText             = attributedString;
self.lblQuote.numberOfLines              = 0;
[self.lblQuote sizeToFit];

enter image description here

Отмена UITextAlignmentJustify, недоступная в iOS 6.

Все возможные решения для обоснованного текста приведены на этой ссылке SO > посмотрите эту страницу и документация предварительного просмотра iOS6.

Ответ 2

Я как-то нашел способ сделать ярлык Justifiy в iOS 7: я просто устанавливаю NSBaselineOffsetAttributeName равным 0.

Не знаю, почему вам нужно добавить этот базовый параметр в iOS 7 (он отлично работает на iOS 6).

NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
        paragraph.alignment = NSTextAlignmentJustified;

NSDictionary *attributes = @{ NSParagraphStyleAttributeName : paragraph,
                                        NSFontAttributeName : self.textLabel.font,
                              NSBaselineOffsetAttributeName : [NSNumber numberWithFloat:0] };

NSAttributedString *str = [[NSAttributedString alloc] initWithString:content 
                                                          attributes:attributes];

self.textLabel.attributedText = str;

Надеюсь, что помогает;)