Latest 1.2.0
Homepage https://github.com/dbowen/NSAttributedString-DDHTML
License BSD Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Platforms ios 7.0, tvos 9.0, watchos 2.0, requires ARC
Authors

NSAttributedString+DDHTML

Simplifies working with attributed strings by allowing you to use HTML to describe formatting behaviors.

NSAttributedString+DDHTML isn’t intended to support full HTML rendering. Instead it provides a quick, effient and light-weight implementation for leveraging attributed strings when utilizing native UIKit interface elements.

License


It is open source and covered by a standard BSD license. That means you have to mention Derek Bowen @ Deloite Digital as the original author of this code.

Requirements


NSAttributedString+DDHTML requires a minimum iOS deployment target of iOS 7.0 because of:

  • NSTextAttachment

Setup


Using CocoaPods

One of the easiest ways to integrate NSAttributedString+DDHTML in your project is to use CocoaPods:

  1. Add the following line to your Podfile:

    pod "NSAttributedString-DDHTML"
  2. In your project directory, run pod update
  3. You should now be able to add #import <NSAttributedString-DDHTML/NSAttributedString+DDHTML.h> to any of your target’s source files to use the library!

Manual

  1. Add NSAttributedString+DDHTML.m/h to your project.
  2. Add libxml2.dylib to the "Link Binary With Libraries" section of your target’s build phase.
  3. Add ${SDKROOT}/usr/include/libxml2 to your project’s Header Search Paths under Build Settings.
  4. Start using it!

Usage


#import "NSAttributedString+DDHTML.h"

...

NSAttributedString *attributedString = [NSAttributedString attributedStringFromHTML:@"My <b>formatted</b> string."];

...

Supported Tags


b, strong – Bold (iOS, watchOS, tvOS)

i – Italics (iOS, watchOS, tvOS)

u – Underline (iOS, watchOS, tvOS)

strike – Strikethrough (iOS, watchOS, tvOS)

stroke – Stroke (iOS, watchOS, tvOS)

  • color: Color of stroke, e.g. stroke="#ff0000"
  • width: Width of stroke, e.g. stroke="2.0"
  • nofill: If present text color will be transparent

shadow – Shadow (iOS, tvOS)

  • offset: Amount to offset shadow from center of text, e.g. offset="{1.0, 1.0}"
  • blurRadius: Radius/thickness of the shadow
  • color: Color of the shadow

font – Font (iOS, watchOS, tvOS)

  • face: Name of font to use, e.g. face="Avenir-Heavy"
  • size: Size of the text, e.g. size="12.0"
  • color: Color of the text, e.g. color="#fafafa"
  • backgroundColor: Color of the text background, e.g. backgroundColor="#333333"

br – Line Break (iOS, watchOS, tvOS)

p – Paragraph (iOS, watchOS, tvOS)

  • 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

img – Image (iOS, tvOS)

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

Latest podspec

{
    "name": "NSAttributedString-DDHTML",
    "version": "1.2.0",
    "license": {
        "type": "BSD",
        "text": "      Redistribution and use in source and binary forms, with or withoutn      modification, are permitted provided that the following conditions are met:n      * Redistributions of source code must retain the above copyrightn        notice, this list of conditions and the following disclaimer.n      * Redistributions in binary form must reproduce the above copyrightn        notice, this list of conditions and the following disclaimer in then        documentation and/or other materials provided with the distribution.n      * Neither the name of the  nor then        names of its contributors may be used to endorse or promote productsn        derived from this software without specific prior written permission.nn      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ANDn      ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDn      WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREn      DISCLAIMED. IN NO EVENT SHALL  BE LIABLE FOR ANYn      DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGESn      (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;n      LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED ANDn      ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORTn      (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THISn      SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.n"
    },
    "summary": "Easily create NSAttributedStrings using HTML.",
    "homepage": "https://github.com/dbowen/NSAttributedString-DDHTML",
    "authors": {
        "Derek Bowen": "[email protected]"
    },
    "source": {
        "git": "https://github.com/dbowen/NSAttributedString-DDHTML.git",
        "tag": "v1.2.0"
    },
    "description": "Simplifies working with NSAttributedString by allowing you to use HTML to describe formatting behaviors.",
    "requires_arc": true,
    "platforms": {
        "ios": "7.0",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "source_files": "NSAttributedString+DDHTML",
    "libraries": "xml2",
    "xcconfig": {
        "HEADER_SEARCH_PATHS": "$(SDKROOT)/usr/include/libxml2"
    }
}

Pin It on Pinterest

Share This