3
votes

How can I display a text like this :

Title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent malesuada vulputate ullamcorper. Nunc facilisis magna vitae augue euismod, ultrices pretium est suscipit. In a lacus ullamcorper, aliquam ante at, lacinia justo. Quisque hendrerit sem eget neque molestie, ac ullamcorper justo molestie. Vestibulum consectetur erat quam, interdum fermentum augue egestas volutpat. Quisque eleifend porttitor tellus, non fermentum nisl. Aliquam mauris sem, congue sed nisl quis, cursus pharetra nisl. Sed tincidunt, diam eu semper interdum, felis metus sollicitudin tortor, at sodales dolor turpis at quam. Vestibulum faucibus nibh eu cursus ullamcorper.

Subtitle

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent malesuada vulputate ullamcorper. Nunc facilisis magna vitae augue euismod, ultrices pretium est suscipit. In a lacus ullamcorper, aliquam ante at, lacinia justo. Quisque hendrerit sem eget neque molestie, ac ullamcorper justo molestie. Vestibulum consectetur erat quam, interdum fermentum augue egestas volutpat. Quisque eleifend porttitor tellus, non fermentum nisl. Aliquam mauris sem, congue sed nisl quis, cursus pharetra nisl. Sed tincidunt, diam eu semper interdum, felis metus sollicitudin tortor, at sodales dolor turpis at quam. Vestibulum faucibus nibh eu cursus ullamcorper.

In a UIAlertView on iOS 7?

I found a method to do that with a UITextView and NSAttributedString but I don't want to use NSRange. I have each title, subtitle and paragraph in a Strings File.

Thanks.

1

1 Answers

3
votes

No, you can't do that. UIAlertView doesn't accept attributed strings as parameters and can not use them in as a message. You will have to roll your own recreation of UIAlertView, or download an existing one from CocoaControls if you want to be able to add a UITextView to the alert.

That being said, when you do figure out how you want to go about displaying the information, you should know that there is an easy way to put an attributed string like this together without having to manually specify the ranges that each attribute should be applied to. Create dictionaries to house the different attribute types that you'll use on the final string, and string a series of attributed strings together. Doing this in the way demonstrated below will apply the selected attributes to the entire string they are applied to.

NSDictionary *titleAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:24.0]};
NSDictionary *subTitleAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:20.0]};

NSMutableAttributedString *finalString = [NSMutableAttributedString new];

[finalString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Title" attributes:titleAttributes]];
[finalString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit."]];
[finalString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Subtitle" attributes:subTitleAttributes]];
[finalString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit."]];