评论UITextView,Rich Text和UIWebView

时间:2011-08-21 18:42:00

标签: ios uiwebview

UITextView不允许使用丰富或程式化的文本,这已不是什么秘密。

目前,我有:

UIView
    UIScrollView
        UILabel, a UIImage,
        UITextView,
        UIButton

我所做的是通过以下方式将整个3部分的肿块滚动起来:

1:使用IB设置基本垂直位置并禁用UITextView的滚动。

2:从我的-viewDidLoad方法中调用我的-repositionSubViewsForTallContent。

-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);

BIG-TIME评论是UIWebView没有.contentSize ivar。

首先,您必须将UIWebView的委托设置为在其.h文件中声明为<UIWebViewDelegate>的类。

[webView_ setDelegate:self];

另请注意,在此课程中,您应覆盖:

- (void )webViewDidFinishLoad:(UIWebView *)webView
{
    // place this magical method here, **not** in -viewDidLoad
    [self repositionSubViewsForTallContent];    
}

我知道如何提取UIScrollView的<{1}}组件:

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以下,即可开展业务。

John Love

0 个答案:

没有答案