0

UITextView で高さを動的に設定したいのですが、うまくいきません。私のコードは次のとおりです。

 [super viewDidLoad];
 DTAttributedTextView *_textView;
contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height)];
_textView = [[DTAttributedTextView alloc] initWithFrame:CGRectMake(0.0, 80.0, self.view.frame.size.width, self.view.frame.size.height)];

UIImage *backgroundImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.epnet.fr%@",[[[currentDicoNew valueForKey:@"image"] valueForKey:@"thumb_rect"] valueForKey:@"url"]]]]];
imageNew = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, 320, 178)];
imageNew.image = backgroundImage;
imageNew.contentMode = UIViewContentModeScaleAspectFill;

CGSize maxImageSize = CGSizeMake(self.view.bounds.size.width - 20.0, self.view.bounds.size.height);
NSString *html = [SundownWrapper convertMarkdownString:[currentDicoNew valueForKey:@"content"]];
NSData *HTMLData = [html dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *options = @{ DTDefaultFontFamily : @"Helvetica",
                           DTDefaultFontSize : [NSNumber numberWithFloat:14.0],
                           DTDefaultLinkColor:[UIColor colorWithRed:0.0/255.0 green:174.0/255.0 blue:239.0/255.0 alpha:1],
                           DTMaxImageSize : [NSValue valueWithCGSize:maxImageSize],
                        };
NSAttributedString *attrString = [[NSAttributedString alloc] initWithHTMLData:HTMLData options:options documentAttributes:nil];

_textView.attributedString = attrString;
_textView.shouldDrawImages = YES;
_textView.shouldDrawLinks = YES;
_textView.textDelegate = self;
[_textView setScrollIndicatorInsets:UIEdgeInsetsMake(0, 0, 44, 0)];
_textView.contentInset = UIEdgeInsetsMake(10, 10, 54, 10);
[_textView.attributedTextContentView setNeedsDisplay];
[_textView setScrollEnabled:NO];
[contentView addSubview:_textView];

MDCParallaxView *parallaxView = [[MDCParallaxView alloc] initWithBackgroundView:imageNew
                                                                 foregroundView:contentView];
parallaxView.frame = CGRectMake(0, 40, 320, self.view.frame.size.height);
parallaxView.backgroundHeight = 100;
parallaxView.scrollView.scrollsToTop = YES;
parallaxView.backgroundInteractionEnabled = YES;
parallaxView.scrollViewDelegate = self;

[self.view addSubview:parallaxView];

高さは 420 (self.view.frame.size.height) ですが、動的コンテンツの高さを取得する方法を知りたいです。これは、viewDidDisapear でこれをコーディングすると機能しますが、ViewDidLoad では機能しないためです。

CGRect frame1;
frame1 = _textView.frame;
frame1.size.height = [_textView contentSize].height;
_textView.frame = frame1;
NSLog(@"%f", frame1.size.height);

では、高さを動的に設定するにはどうすればよいですか? どうもありがとう

4

2 に答える 2