Latest 1.0.9
Homepage https://github.com/623637646/YNRichLabel
License MIT
Platforms ios 7.0
Dependencies YNXMLParser
Authors

XML rich text label

How to use?

  1. init just like useing UILabel

    YNRichLabel *label = [[YNRichLabel alloc] init];
  2. set normalAttributes, This is the normal attributes for rich text

    label.normalAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:20],
                          NSForegroundColorAttributeName: [UIColor redColor]};
  3. set up with YNRichTagAdapter

for <a href="www.google.com">this is content</a>

[label addTagAdapter:({
        YNRichTagAdapter *adapter = [[YNRichTagAdapter alloc] init];
        adapter.tagName = @"a";
        adapter.attributesBlock = ^NSDictionary<NSAttributedStringKey,id> *(YNRichTagModel *model, NSString *text, NSDictionary<NSAttributedStringKey,id> *normalAttributes) {
            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:normalAttributes];
            [dic addEntriesFromDictionary:@{NSForegroundColorAttributeName: [UIColor blueColor]
                                            }];
            return dic;
        };
        adapter.clickBlock = ^(YNRichTagModel *model) {
            NSLog(@"%@",model.attributes);
        };
        adapter;
    })];

for <b>this is content</b>

[label addTagAdapter:({
        YNRichTagAdapter *adapter = [[YNRichTagAdapter alloc] init];
        adapter.tagName = @"b";
        adapter.attributesBlock = ^NSDictionary<NSAttributedStringKey,id> *(YNRichTagModel *model, NSString *text, NSDictionary<NSAttributedStringKey,id> *normalAttributes) {
            NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:normalAttributes];
            [dic addEntriesFromDictionary:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:24]
                                            }];
            return dic;
        };
        adapter;
    })];

for <br>

[label addTagAdapter:({
        YNRichTagAdapter *adapter = [[YNRichTagAdapter alloc] init];
        adapter.tagName = @"br";
        adapter.textBlock = ^NSString *(YNRichTagModel *model) {
            return @"n";
        };
        adapter;
    })];

for ??? any HTML tag what you want~~~

  1. set text

    label.text = @"这里是<br/>普通内容n<a href="www.google.com">这里是a的内容</a>n<b>这里是b的内容</b>n<a>这里是a<b>嵌套</b>b的内容</a>n<b>这里是b<a>嵌套</a>a的内容</b>n这里是普通内容n<d>这里是d的内容</d>n这里是普通内容<br/>换行标签<br/><br/><br/>Free for min order<br/> of <b>SGD</b> 20.00 from<a href="www.google.com">Taobao Collection</a>";
  2. done, have fun.

Demo

you can run demo in YNRichLabel.xcworkspace, just pod install it

Requirements

iOS 7.0

Latest podspec

{
    "name": "YNRichLabel",
    "version": "1.0.9",
    "summary": "XML rich text label",
    "description": "XML rich text label, Great!",
    "homepage": "https://github.com/623637646/YNRichLabel",
    "license": "MIT",
    "authors": {
        "u7801u7334": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/623637646/YNRichLabel.git",
        "tag": "1.0.9"
    },
    "source_files": "YNRichLabel/**/*.{h,m}",
    "dependencies": {
        "YNXMLParser": []
    }
}

Pin It on Pinterest

Share This