zoukankan      html  css  js  c++  java
  • UIWebView 里设置Text的自定义高度

    /*NSString *text = [NSString stringWithFormat:@"<html> \n"
    "<head> \n"
    "<style type=\"text/css\"> \n"
    "body{font-family:\"%@\";font-size:%f;} \n"
    "</style> \n"
    "</head> \n"
    "<body><div id=\"content\">%@</div></body> \n"
    "</html>",@"宋体",20.0,news.content];

    contentView.delegate = self;
    contentView.scalesPageToFit = YES;
    [contentView setOpaque:NO];
    [contentView setBackgroundColor:[UIColor clearColor]];
    [contentView loadHTMLString:text baseURL:nil];
    */

    /*
    [lblContent setText:text];
    [lblContent setFont:[UIFont systemFontOfSize:16]];
    [lblContent setNumberOfLines:0];
    CGSize contentSize = [text sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:CGSizeMake(300, 9999) lineBreakMode:lblContent.lineBreakMode];
    [lblContent sizeToFit];
    [lblContent setFrame:CGRectMake(10, startYLoc+10, 300, contentSize.height)];

    startYLoc += contentSize.height + 20;
    */

    //[self.detailScroll setContentSize:CGSizeMake(320, startYLoc)];
     /* 获取webview的高度
    CGSize actualSize = [webView sizeThatFits:CGSizeZero];
    CGRect contentFrame = webView.frame;
    contentFrame.size.height = actualSize.height;
    detailScroll.contentSize = CGSizeMake(320, contentFrame.size.height+60.0);
    webView.frame = contentFrame;
    */
    //CGSize actualSize = [webView sizeThatFits:CGSizeZero];
    //[contentView sizeToFit];
    /*
    if(webView != contentView)
    return;

    float height;
    NSString *heightString = [contentView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"content\").offsetHeight;"];
    NSLog(@"HeightString:%@",heightString);
    height = [heightString floatValue];
    contentView.frame = CGRectMake(contentView.frame.origin.x, contentView.frame.origin.y, 310, height);
    NSLog(@"height :%f", height);
    height = contentView.frame.origin.y + height;


    [detailScroll setContentSize:CGSizeMake(320, height)];

    NSLog(@"ScrollView height :%f",detailScroll.frame.size.height);

    //[self.detailScroll setContentSize:CGSizeMake(320,[heightString intValue])];
    //CGRect WebViewFrame = contentView.frame;
    //[contentView setFrame:CGRectMake(WebViewFrame.origin.x, WebViewFrame.origin.y, 310, [heightString intValue])];
    //contentView.frame = CGRectMake(contentView.frame.origin.x, contentView.frame.origin.y, contentView.frame.size.width,actualHeight);
    //NSLog(@"ContentView'height:%@",contentView.frame.size.height);
    //[self.detailScroll setContentSize:CGSizeMake(320, contentView.frame.size.height)];
    //actualHeight = contentView.frame.origin.y + actualHeight +70;
    //detailScroll.contentSize = CGSizeMake(320, actualHeight+20);
    */

    正则表达式,去除html

    //NSString *text = [news.content stringByReplacingOccurrencesOfRegex:@"<[^>]+>" withString:@" "];

  • 相关阅读:
    Kali,CentOS 配置静态网络与开启SSH服务【附VMware中配置】
    httpHelper请求辅助类
    请求后的数据处理
    Viewcontroller基类
    上拉下拉基类
    获取cell中的button在整个屏幕上的位置
    Object-C反射读取实体属性和值
    xcode在代码中查找中文
    编写xcode5插件需要增加DVTPlugInCompatibilityUUIDs
    c# 扩展方法
  • 原文地址:https://www.cnblogs.com/dm521/p/2281018.html
Copyright © 2011-2022 走看看