UITextView cannot be selected with textContainer

I am using UITextView with attribute textContainerand row attribute ...

UITextView * textView = [[UITextView alloc] initWithFrame: textViewFrame textContainer: textContainer];

But this text box has become unacceptable.

I tried using subClass UITextView and returning the YESto method canBecomeFirstResponder, but it is still not selected.

How to solve this problem?


This is part of my code.

NSString * decodedHtmlString = [[contentString stringByDecodingHTMLEntities] stringWithNewLinesAsBRs];

NSString * plainText = [decodedHtmlString stringByConvertingHTMLToPlainText];

NSData * dataString = [decodedHtmlString dataUsingEncoding:NSUnicodeStringEncoding allowLossyConversion:NO];

NSDictionary * attributedOptions = [NSDictionary dictionaryWithObjectsAndKeys:
                                    NSHTMLTextDocumentType, NSDocumentTypeDocumentAttribute
                                    , nil];



NSAttributedString * attributesString = [[NSAttributedString alloc] initWithData:dataString
                                                                         options:attributedOptions
                                                              documentAttributes:nil
                                                                           error:nil];


/////direction
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = NSTextAlignmentRight;


NSMutableAttributedString * mutableAttrString = [[NSMutableAttributedString alloc] initWithAttributedString:attributesString];
[mutableAttrString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:29.0] range:NSMakeRange(0, plainText.length)];
[mutableAttrString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, plainText.length)];



NSTextStorage * textStorage = [[NSTextStorage alloc] initWithAttributedString:mutableAttrString];
NSLayoutManager * layoutManager = [[NSLayoutManager alloc] init];
[textStorage addLayoutManager:layoutManager];


NSUInteger lastRenderedGlyph = 0;
CGFloat currentXOffset = 0;
while (lastRenderedGlyph < layoutManager.numberOfGlyphs) {

    CGRect textViewFrame = CGRectMake(currentXOffset, 0, 500, 700);
    CGSize columnSize = textViewFrame.size;

    NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:columnSize];
    [layoutManager addTextContainer:textContainer];

    UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame
                                               textContainer:textContainer];
    [textView setSelectable:YES];
    textView.scrollEnabled = NO;

    currentXOffset += CGRectGetWidth(textViewFrame);

    [self.scrollView addSubView:textView];
    lastRenderedGlyph = NSMaxRange([layoutManager glyphRangeForTextContainer:textContainer]);
}
+4
source share
2 answers

, UITextView textContainer. , String textContainer, attributeText UITextView.

    NSAttributedString * subAttributedString = [mutableAttrString attributedSubstringFromRange:[layoutManager glyphRangeForTextContainer:textContainer]];
    [textView setAttributedText: subAttributedString];

.

+3

NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:Size];

// create the UITextView for this column        
UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame
                                           textContainer:textContainer];
0

All Articles