Question

I am trying to load a UITextView with content from instances of a NSManagedObject subclass (verses in a Bible reader app).

My UITextView is loaded by iterating through the verses in a selected chapter and appending each consecutive verse.

NSArray *selectedVerses = [[Store sharedStore] versesForBookName:selectedBook
                                                   ChapterNumber:selectedChapterNum];
displayString = @"";
for (Verse *v in selectedVerses) {
    NSMutableString *addedString =
    [NSMutableString stringWithFormat:@"%d %@", [v versenum], [v verse]];
    displayString = [NSMutableString stringWithFormat:@"%@ %@", addedString, displayString];
}
NSString *title = [NSString stringWithFormat:@"%@ %@", selectedBook, selectedChapter];
[self setTitle:title];
[[self readerTextView] setNeedsDisplay];
[[self readerTextView] setText:displayString];

The above code generates the correct view, but only allows for one size of text for the entire UITextView.

I would like to have the verse number that precedes each verse to be a smaller size font than its verse, but have not found a way to make it work. I've been reading through the documentation, and it seems that this should be possible with TextKit and CoreText through the use of attributed strings, but I can't seem to get this to compile.

I do not want to load the view as a UIWebView.

Any suggestions for this are greatly appreciated.

Was it helpful?

Solution

You're looking for NSAttributedString and NSMutableAttributedString. You should read Introduction to Attributed String Programming Guide. They're generally like normal strings, but additionally contain attributes with ranges to which they apply. One more method that would be helpful to you is:

[self readerTextView].attributedText = yourAttributedString;

If you have some specific problems with attributed strings, please post your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top