Latest 0.1.1
Homepage https://github.com/pigigaldi/DKHTMLAttributedString
License MIT
Platforms ios 9.0

Version
License
Platform

This pod can helps developers handling HTML strings without any effort. Just pass a String object to given method and you’ll get an NSAttributedString object that you can display inside an UITextView or an UILabel.

This library is a Swift port of NSAttributedString-DDHTML and, since this: "it’s not intended to support full HTML rendering. Instead it provides a quick, efficent and light-weight implementation for leveraging attributed strings when utilizing native UIKit interface elements."

Requirements

DKHTMLAttributedString requires a minimum iOS deployment target of iOS 9.0.

Setup

CocoaPods

One of the easiest ways to integrate DKHTMLAttributedString in your project is to use CocoaPods:

  1. Add the following line to your Podfile:

    pod 'DKHTMLAttributedString'
  2. In your project directory, run pod update
  3. You should now be done.

Usage

import DKHTMLAttributedString
let htmlString = "<b>Hello</b> <i>World!</i>"
let attributedString = DKHTMLAttributedString.attributedString(from: htmlString)
self.textView.attributedText = attributedString

Full method

open class func attributedString(from htmlString: String?, 
                                 normalFont: UIFont? = nil, 
                                 boldFont: UIFont? = nil, 
                                 italicFont: UIFont? = nil, 
                                 imageMap: [String: UIImage]? = nil
) -> NSAttributedString?

Supported Tags

1. <b>

2. <strong>

3. <i>
4. <em>

5. <u>

6. <strike>

7. <br>

8. <p>

  • align: Alignment of text, e.g. align="center"
    • Available values: left, center, right, justify
  • lineBreakMode: How to handle text which doesn’t fit horizontally in the view
    • Available values: WordWrapping, CharWrapping, Clipping, TruncatingHead, TruncatingTail, TruncatingMiddle
  • firstLineHeadIndent
  • headIndent
  • hyphenationFactor
  • lineHeightMultiple
  • lineSpacing
  • maximumLineHeight
  • minimumLineHeight
  • paragraphSpacing
  • paragraphSpacingBefore
  • tailIndent

9. <img>

  • src : key in imageMap parameter
  • width : px
  • height : px

License

MIT License. See LICENSE file for further information.

Latest podspec

{
    "name": "DKHTMLAttributedString",
    "version": "0.1.1",
    "summary": "Convert HTML string to NSAttributedString object.",
    "homepage": "https://github.com/pigigaldi/DKHTMLAttributedString",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "description": "This pod can helps developers handling HTML strings without any effort. Just pass a string and you'll get an NSAttributedString object that you can display inside an UITextView or an UILabel. (This library is based on `https://github.com/dbowen/NSAttributedString-DDHTML`)",
    "authors": "Pierluigi Galdi",
    "social_media_url": "https://twitter.com/pigigaldi",
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/pigigaldi/DKHTMLAttributedString.git",
        "tag": "0.1.1"
    },
    "source_files": [
        "DKHTMLAttributedString/**/*.swift",
        "DKHTMLAttributedString/**/*.h"
    ],
    "libraries": "xml2",
    "xcconfig": {
        "HEADER_SEARCH_PATHS": "$(SDKROOT)/usr/include/libxml2"
    },
    "swift_version": "4.1"
}

Pin It on Pinterest

Share This