IOS開發在H5頁面創建列表,類似新聞頁底部推薦更多

效果如下:


廢話不多說,直接上代碼

- (NSString *)jsFunction { return @"function sendCommand(cmd,param){var url='testapp:'+cmd+':'+param;document.location = url;}";}


-(void)parseData{ NSString *tempStrring =[self htmlEntityDecode:_info.content]; NSString *strring =[NSString stringWithFormat:@"%",tempStrring];? ? NSMutableString *contentstr=[NSMutableString stringWithString:strring];? ? NSString *puttimestr=[NSString stringWithFormat:@"%@? %@",_info.newsOrigin,_info.puttime];? ? [contentstr insertString:puttimestr atIndex:0];? ? NSString *titlestr=[NSString stringWithFormat:@"%@",_info.title];? ? [contentstr insertString:titlestr atIndex:0];? ? ? ? ??

? NSString *titlestr1 = [NSString stringWithFormat:@"猜你喜歡"];??

? [contentstr appendString:titlestr1];? ? ? ?

?for (NSDictionary *item in _info.newslab) { ? ? ? ?

NSString *titlestr2 = [NSString stringWithFormat:@"%@ · %@%@",[self jsFunction],[NSString stringWithFormat:@"sendCommand(\"wangzhan\",this.children[1].innerHTML)"],[item valueForKey:@"news_title"],[item valueForKey:@"news_id"]];? ? ?

?? [contentstr appendString:titlestr2];??

? }? ? ? ? ? ? ? ? ? ??

webView1=[[UIWebView alloc]init];? ?

?webView1.delegate = self;? ??

webView1.backgroundColor=[UIColor whiteColor];? ?

?NSString *htmlpath=[[NSBundle mainBundle]pathForResource:@"Content" ofType:@"html"];? ?

?? ? [webView1 loadHTMLString:contentstr? baseURL:[NSURL fileURLWithPath:htmlpath]];? ?

?webView1.frame=CGRectMake(0,44, DEXx, DEXy - 44);? ? [webView1 setDelegate:self];??

? //? ? 取消滾動條和背景??

? for (UIView *aView in [webView1 subviews]) ? { ? ?

? ? if ([aView isKindOfClass:[UIScrollView class]]) ? ? ? ?{ ? ? ? ? ??

?[(UIScrollView *)aView setShowsVerticalScrollIndicator:NO];?

//右側的滾動條 (水平的類似)? ? ? ? ? ??

for (UIView *shadowView in aView.subviews) ?{

?if ([shadowView isKindOfClass:[UIImageView class]]) ?{? ? ? ? ? ? ? ? ? ? shadowView.hidden = YES;?

?//上下滾動出邊界時的黑色的圖片 也就是拖拽后的上下陰影? ? ? ? ? ??

? ? }

? ? ? ? ? ?}? ? ? ??

}??

? }? ? ??

? [self.view addSubview:webView1];}

// **********? 字符串轉義? *************

-(NSString *)htmlEntityDecode:(NSString *)string{? ? string = [string stringByReplacingOccurrencesOfString:@"&" withString:@"&"];? ? //中文換行? ? string = [string stringByReplacingOccurrencesOfString:@" withString:@"

"];? ??

//英文換行? ? string = [string stringByReplacingOccurrencesOfString:@"
" withString:@""];? ?

?//字體加粗? ? string = [string stringByReplacingOccurrencesOfString:@"" withString:@""];

? ? string = [string stringByReplacingOccurrencesOfString:@"" withString:@""];?

?? //字體? 斜體? ? string = [string stringByReplacingOccurrencesOfString:@"" withString:@""];

? string = [string stringByReplacingOccurrencesOfString:@"" withString:@""];? ? string = [string stringByReplacingOccurrencesOfString:@"<" withString:@"<"];? ? string = [string stringByReplacingOccurrencesOfString:@">" withString:@">"];? ? //雙引號? ? string = [string stringByReplacingOccurrencesOfString:@""" withString:@"'"];? ? string = [string stringByReplacingOccurrencesOfString:@""" withString:@"'"];? ? string=[string stringByReplacingOccurrencesOfString:@"img" withString:@"img style='width:310px;'"];? ? ? ? string=[string stringByReplacingOccurrencesOfString:@"height" withString:@""];? ? string = [string stringByReplacingOccurrencesOfString:@" " withString:@" "];? ? ? ? return string;}#pragma mark -- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {? ? NSString *requestString = [[request URL] absoluteString];//獲取請求的絕對路徑.? ? NSArray *components = [requestString componentsSeparatedByString:@":"];//提交請求時候分割參數的分隔符? ? if ([components count] > 1 && [(NSString *)[components objectAtIndex:0] isEqualToString:@"testapp"]) {? ? ?

?? //過濾請求是否是我們需要的.不需要的請求不進入條件? ? ? ?

?if([(NSString *)[components objectAtIndex:1] isEqualToString:@"wangzhan"])? ? ? ? {? ? ? ? ??

? NSString *message = (NSString *)[components objectAtIndex:2]; ? ? ? ? ? ? ? ? ? ??

WZInfomationFileInfo *subFile = [[WZInfomationFileInfo alloc] init];? ? ? ? ? ?

?subFile.ID = message;? ? ? ? ? ?

?WZInfomationDetilVC *detilVC = [[WZInfomationDetilVC alloc] init];? ? ? ? ? ? detilVC.info = subFile;? ? ? ? ? ??

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:detilVC];? ? ? ? ??

? [self presentViewController:nav animated:YES completion:nil];? ? ?

?? }

? ? ? ? return NO;??

? }? ?

?return YES;}

謝謝支持!!!

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容