• 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:@" "];

  • 相关阅读:
    Android见招拆招五:XML匹配问题、XML资源引用的必要性
    Android见招拆招四:Manifest.xml内容神秘还原
    Android学习笔记三:Intent实现页面跳转
    Android学习笔记二:(布局)Linear Layout、Layout weight测试
    Android见招拆招三:Eclipse软件误报
    Android学习笔记一:(布局)fill_parent、wrap_content、match_parent实例测试
    文件读写(笔记)
    常用的异常
    面向过程、函数式、面向对象
    time&datetime&random模块
  • 原文地址:https://www.cnblogs.com/dm521/p/2281018.html
Copyright © 2020-2023  润新知