HTML table on a UIView in Swift - html

I am trying to display a table in a UIView that is delivered in html form from a server. It looks like these tables might be slightly different, but they obviously display correctly in a browser.
Is there anyone that can recommend a library that is useful for this?
Thanks for any help.
Edit screenshot of the table cell
The 'textBlock' gets built up with text, images and hopefully tables. All by appending the attributed text. I can't see a way to switch that label out for a webView.

If you want to display HTML in iOS it's better to use WKWebView instead of UIView. Then you can use loadHTMLString method:
webView.loadHTMLString("<html><body><p>Hello!</p></body></html>", baseURL: nil)

Related

How can I extract the first paragraph of web page contents in a WKWebView

In a WKWebView, if I need webpage's title,I can get it via webView.title.
But when the first paragraph of webpage's contents is needed,there is no easy solution. Any advice and suggestions will be greatly appreciated,thanks.
If you control the HTML then you could use a query selector like:
document.querySelector("#content").innerText.split("\n")[0]
Note: You can inject javascript similar to this answer: Get HTML from WKWebview in Swift

What's the best solution to display HTML Content combined with native Content on iOS?

I'm searching for a good solution on iOS to display HTML Content combined with native Content on iOS
For Example in my News App, the DetailView looks like:
Header: Native UILabel
Picture Gallery: Native ScrollView with Paging
Content of the Article HTML (first Part); can include external embeds like Twitter, Facebook
Native BannerView
Content of the Article HTML (last Part) ; can include external embeds like Twitter, Facebook
Related Articles, Native UIView
It becomes really complicated because I've to put a UIWebView within a Scrollview: Scrollable Content into Scrollable Content. The height of each Webview needs to be set manually.
What is the best solution to implement this? Are there alternatives? How other News Apps do this (Like NewsRepublic)?
Use tableview or collection view (as NewsRepublic does)
You will have cells for the type you want to display
E.g:
Header: Native UILabel - Basic tableview cell
Picture Gallery: Native ScrollView with Paging - Tableview cell with page controller
Content of the Article HTML (first Part); UITableview cell with NSAttributed string (or webview)
and so on.
Note that having a UIWebView inside a cell negatively affects the scrolling performance, so I would use a library that creates an NSAttributedString from it, like this
Since ios 8 you can easily set up a tableview with dynamic cell heights using only auto layout and automatic dimension:
tableView.rowHeight = UITableViewAutomaticDimension
Try creating a seprate subviews view as per your requirement and than add them in UICollectionView & show that collection view on screen.
Divide your view into smaller subViews and than add them togather.
As per your question your subviews can be:
Header View (contatins UILabel)
Picture gallery (can use UIScrollView Or UICollectionView)
UIWebView
UIview for Banner
... and so on ...
Add above subviews in UICollectionView as cells.
Use CollectionView or TableView.
Add Webview, Label & textField in Cell and set UserInteractionEnable NO.
Set dynamic height of All Cell As requirement.
The best solution to display HTML content combined with native content is to use RTLabel.
RTLabel works like UILabel, but supports html-like markups for rich text display. It is based on Core Text, so it supports some of the stuff that Core Text supports.
You can get it from the following link.
https://github.com/honcheng/RTLabel

It is possible to display html content in iOS7 UIAlertView?

Do you know if it's possible to display some html content (through UIWebView or directly) in the UIAlertview component, on iOS7? The "addSubview" method seems to be no more available...
Thank you for your help!
Unfortunately there wont be UIAlertView with custom views anymore, nor contentView which Apple changed its mind about, you need to use a custom control like a HUD.
A good alternative will be SVProgressHUD, according to many threads in Apple's forum.

iOS - Converting HTML to Normal text

In my application, I'm receiving an html file from a news server.
After receiving, I want to remove the tags, images, URL anchors, etc and just show the text in text view.
There's a website which functions similar to the one that I'm looking for. The website takes html as input and removes the tags and displays just plain text as result. I want to achieve similar function in my app and display only the text from the news received.
Any libraries or open source web services available for this?
There is this library here, you could do something like this:
NSString *htmlStripped = [[NSAttributedString attributedStringWithHTML:DATA_FOR_MY_HTML options:nil] string];

Cocoa: Display HTML from string

How can I display properly formatted text from an NSString, that just happens to be HTML. The html is coming from the stack overflow API.
You can create a NSAttributedString from HTML. You then draw it as you would draw any other NSAttributedString.
If your tags are accurate and you are programming for OS X (or iPhone 4.0+), you can use NSAttributedString's – initWithHTML:documentAttributes:, and then draw that directly.
Unfortunately, the iPhone OS' UIKit does not contain NSAttributedString pre-4.0. The current recommendation from the developer docs is to use a UIWebView, which sucks. An alternative might be the Three20 library, which contains TTStyledText -- that looks like it might do the job.
You could have a WebView, and tell the WebView's mainFrame to load the HTML string.
If you meant to ask about Cocoa Touch, UIWebView has an equivalent method for you.