Не секрет, что UITextView не разрешает форматированный или стилизованный текст.
В настоящее время у меня есть:
UIView
UIScrollView
UILabel, a UIImage,
UITextView,
UIButton
То, что мне удалось сделать, это сделать все 3-прокручиваемую часть фрагмента с помощью:
1: используйте IB для установки элементарных вертикальных положений и отключите прокрутку для UITextView.
2: вызовmy –repositionSubViewsForTallContent из моего метода –viewDidLoad.
-repositionSubViewsForTallContent
делает:
// elongate the height of the UITextView.frame
a: get the contentHeight of the UITextView
textViewContentHeight = textView_.contentSize.height;
followed by:
textView_.frame = CGRectMake(sameOriginX, sameOriginY,
sameWidth, textViewContentHeight);
// move the UIButton to below the now super-tall UITextView
b: newButtonOriginY = textViewOriginY + textViewContentHeight +
kButtonSpacing;
followed by:
button_frame = CGRectMake(sameButtonOriginX,
newButtonOriginY,
sameButtonWidth,
sameButtonHeight);
// compute a new height of the UIScrollView to include
// the now very tall UITextView and the moved-down UIButton:
c: newWholeViewScrollerHeight = newButtonOriginY + buttonHeight;
// finally, set it
d: wholeViewScroller_.contentSize =
CGSizeMake(sameOleWholeViewScrollerWidth,
newWholeViewScrollerHeight);
Большим недостатком является то, что UIWebView
не имеет .contentSize
ivar.
Сначала необходимо установить делегат UIWebView
для класса, который объявлен как <UIWebViewDelegate>
в его файле .h.
[webView_ setDelegate:self];
Также обратите внимание, что в этом классе вы должны переопределить:
- (void )webViewDidFinishLoad:(UIWebView *)webView
{
// place this magical method here, **not** in -viewDidLoad
[self repositionSubViewsForTallContent];
}
Я знаю, как извлечь UIScrollView
компонент UIWebView
:
NSString *scrollViewInsideWebViewHeightStr = [webView_ stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"];
CGFloat webViewContentHeight = [scrollViewInsideWebViewHeightStr floatValue];
или:
UIScrollView *scrollViewInsideWebView = [[webView_ subviews] lastObject];
CGFloat webViewContentHeight = scrollViewInsideWebView.contentSize.height;
Учитывая эту информацию, вы можете теперь установить webView_.frame
на webViewContentHeight
, а также переместить UIButton
ниже UIWebView
, и вы в бизнесе.
Джон Лав