Giter Site home page Giter Site logo

yichizhang / htmlattributedstring Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mmislam101/htmlattributedstring

6.0 2.0 1.0 173 KB

Don't mess with NSRanges anymore; Mark up your strings for quick attributes

License: The Unlicense

Objective-C 93.31% Ruby 6.69%

htmlattributedstring's Introduction

HTMLAttributedString

Don't mess with NSRanges anymore; Mark up your strings for quick attributes.

Imagine what you can now do with push notifications by bolding or italicizing words in the payload! Or imagine how you can create stylized descriptions and instructions on your UILabels!

HTMLAttributedString Example

HTMLAttributedString uses the power of iOS 7.0's initWithData:options:documentAttributes:error: to bring you the power of HTML and CSS into your everyday iOS development needs.

If you want to do quick styling on any labels and text that shows up on your iOS app, or be able to pass styling through internet to your application, you can use HTMLAttributedString class to accomplish the deed.

###Setup Init with:

HTMLAttributedString *string  = [[HTMLAttributedString alloc] initWithHtml:@"<h1>Header</h1> Test string." andBodyFont:[UIFont fontWithName:@"Helvetica" size:18.0]];
NSAttributedString *attributedString = string.attributedString;

But you can also get a quick string by:

NSAttributedText *attributedString = [HTMLAttributedString attributedStringWithHtml:@"<h2>Quick Header</h2> Isn't that simple?" andBodyFont:[UIFont fontWithName:@"Helvetica" size:12.0]];

###Controls You can add CSS rules and remove them or clear them using the following:

- (void)addCssAttribute:(NSString *)cssAttribute;
- (void)removeCssAttribute:(NSString *)cssAttribute;
- (void)clearCssAttributes;

Example:

HTMLAttributedString *string  = [[HTMLAttributedString alloc] initWithHtml:@"<h1>Header</h1> Test string." withFont:[UIFont fontWithName:@"Helvetica" size:18.0]];
[string addCssAttribute:@"h1{font-family : 'Avenir-Roman'; font-size : 24px;}"];

And you can change the body font with the property:

@property (nonatomic, strong) UIFont *bodyFont;

##That's it! Enjoy!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.