Calculate UIWebView height depending on its content

后端 未结 2 1722
栀梦
栀梦 2020-12-14 13:39

I have a class named Announcement, it has a Title (NSString), a Publishing Date (NSString) and a Body<

2条回答
  •  被撕碎了的回忆
    2020-12-14 14:30

    In webview delegate method, just try with below code:

    - (void)webViewDidFinishLoad:(UIWebView *)webView{
        [webviewTopicDesc sizeToFit];
        [webviewTopicDesc setFrame:CGRectMake(webviewTopicDesc.frame.origin.x, webviewTopicDesc.frame.origin.y, 300.0, webviewTopicDesc.frame.size.height)];
    }
    

    Before that, make the webview height as 5.0.

    Hope it helps to you.

    Here, you can get dynamic height based on string.

    -(CGSize)getDynemicHeight:(int)pintFixWidth :(NSString *)pstrText
    {
    CGSize maximumSize=CGSizeMake(pintFixWidth, g_Max_Width);
    UIFont *myFont = [UIFont fontWithName:g_Default_Font_Name size:g_Default_Font_Size];// font used for label
    myFont=[UIFont boldSystemFontOfSize:g_Default_Font_Size];
    
    CGSize sizeS = [pstrText sizeWithFont:myFont 
                       constrainedToSize:maximumSize 
                           lineBreakMode:UILineBreakModeWordWrap];
    
    sizeS.height=sizeS.height+39;
    
    return sizeS;
    }
    

    Here, you have to fix the width and font-size with font-style.

    May be it helps to you.

提交回复
热议问题