如何使用UIActivityViewController,从HTML中分享数据解析出文章(文章包含图像和表单)?

问题描述:

这是我的代码:如何使用UIActivityViewController,从HTML中分享数据解析出文章(文章包含图像和表单)?

如何从HTML解析共享数据?

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[webView] applicationActivities:nil]; 
if ([[UIDevice currentDevice].model isEqualToString:@"iPad"]) { 
    UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC]; 
    [popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 
} else { 
    [self presentViewController:activityVC animated:YES completion:nil]; 
} 

这是我的图像数据

<p style='font-family:宋体;font-size:13.8pt;word-wrap:break-word;text-align:justify;letter-spacing:0.1em;LINE-HEIGHT:1.3; '>Schematic diagram </p><img style='width:100%;' src='http://114.255.183.85:8080/infoPush/statics/content/14888508222440.jpg'/><p style='font-family:宋体;font-size:13.8pt;word-wrap:break-word;text-align:justify;letter-spacing:0.1em;LINE-HEIGHT:1.3; '> </p><p style='font-family:宋体;font-size:13.8pt;word-wrap:break-word;text-align:justify;letter-spacing:0.1em;LINE-HEIGHT:1.3; '> I want to share is like this </p>

我想分享的是这样的: shareImage

这是我的表单中的数据

<p style='font-family:宋体;font-size:13.8pt;word-wrap:break-word;text-align:justify;letter-spacing:0.1em;LINE-HEIGHT:1.3; '>全球手机销量情况表 </p><table border='1'><tr><td rowspan='2'>公司</td><td colspan='2' >2013年第三季度</td><td colspan='2' >2012年第三季度</td></tr><tr><td>万台</td><td>市场份额</td><td>万台</td><td>市场份额</td></tr><tr><td>三星</td><td>11705.4</td><td>25.7%</td><td>9795.7</td><td>22.7%</td></tr><tr><td>诺基亚</td><td>6304.8</td><td>13.8%</td><td>8230.1</td><td>19.1%</td></tr><tr><td>苹果</td><td>3033.0</td><td>6.7%</td><td>2462.0</td><td>5.7%</td></tr><tr><td>LG</td><td>1803.1</td><td>4.0%</td><td>1396.9</td><td>3.2%</td></tr><tr><td>中兴</td><td>1369.6</td><td>3.0%</td><td>1660.6</td><td>3.9%</td></tr><tr><td>其它</td><td>15600.5</td><td>34.2%</td><td>15370.1</td><td>35.7%</td></tr><tr><td>总计</td><td>45564.2</td><td>100.0%</td><td>43102.4</td><td>100.0%</td></tr></table>

我想分享的是这样的: FormImage

- 斯威夫特3 -

// you can share image,string,url, and data. convert your html to data. 
let sharingItem = [image,str,url,data] 

let activityViewController = UIActivityViewController(activityItems: sharingItem, applicationActivities: nil) 

activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ] 

self.present(activityViewController, animated: true, completion: nil) 
+0

谢谢你的好意 – HeroG

+0

雁是帮助FUL然后appruv .. –

+0

谢谢您的回答,但你的回答没有帮助我... – HeroG

我已经解决了这个问题,具体方法如下:

我用这个方法到WebView截图,然后分享图片后可以实现截图:共享UIWebView。

- (UIImage *)imageRepresentation{ 

CGSize boundsSize = self.view.bounds.size; 
CGFloat boundsWidth = self.view.bounds.size.width; 
CGFloat boundsHeight = self.view.bounds.size.height; 

CGPoint offset = self.webView.scrollView.contentOffset; 
[self.webView.scrollView setContentOffset:CGPointMake(0, 0)]; 

CGFloat contentHeight = self.webView.scrollView.contentSize.height; 
NSMutableArray *images = [NSMutableArray array]; 
while (contentHeight > 0) { 
    UIGraphicsBeginImageContext(boundsSize); 
    [self.webView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    [images addObject:image]; 

    CGFloat offsetY = self.webView.scrollView.contentOffset.y; 
    [self.webView.scrollView setContentOffset:CGPointMake(0, offsetY + boundsHeight)]; 
    contentHeight -= boundsHeight; 
} 
[self.webView.scrollView setContentOffset:offset]; 

UIGraphicsBeginImageContext(self.webView.scrollView.contentSize); 
[images enumerateObjectsUsingBlock:^(UIImage *image, NSUInteger idx, BOOL *stop) { 
    [image drawInRect:CGRectMake(0, boundsHeight * idx, boundsWidth, boundsHeight)]; 
}]; 
UIImage *fullImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
return fullImage; 

}

这些都是截图分享图片:

Contains pictures of articles

enter image description here