现在的位置: 首页 > 综合 > 正文

UIWebView 里设置Text的自定义高度

2011年02月03日 ⁄ 综合 ⁄ 共 2410字 ⁄ 字号 评论关闭
/*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:@" "];

抱歉!评论已关闭.