Latest 2.1.0
Homepage https://github.com/changsanjiang/SJAttributesFactory
License MIT
Platforms ios 8.0
Frameworks UIKit
Authors

SJAttributesFactory

Objc

pod 'SJAttributesFactory'

Swift

pod 'SJAttributesStringMaker'

use in swift:

    let text = NSAttributedString.sj.makeText { (make) in
        make.font(.boldSystemFont(ofSize: 20)).textColor(.black).lineSpacing(8)
        make.append("Hello world!")
    }

    // It's equivalent to below code.

    let paragraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
    paragraphStyle.lineSpacing = 8
    let attributes = [NSAttributedString.Key.font:UIFont.boldSystemFont(ofSize: 20),
                      NSAttributedString.Key.foregroundColor:UIColor.black,
                      NSAttributedString.Key.paragraphStyle:paragraphStyle]
    let text1 = NSAttributedString.init(string: "Hello world!", attributes: attributes)

use in Objc:

    NSAttributedString *text = [NSAttributedString sj_UIKitText:^(id<SJUIKitTextMakerProtocol>  _Nonnull make) {
    make.font([UIFont boldSystemFontOfSize:20]).textColor(UIColor.blackColor).lineSpacing(8);

    make.append(@":Image -");
    make.appendImage(^(id<SJUTImageAttachment>  _Nonnull make) {
        make.image = [UIImage imageNamed:@"sample2"];
        make.bounds = CGRectMake(0, 0, 30, 30);
    });

    make.append(@"n");
    make.append(@":UnderLine").underLine(^(id<SJUTDecoration>  _Nonnull make) {
        make.style = NSUnderlineStyleSingle;
        make.color = UIColor.greenColor;
    });

    make.append(@"n");
    make.append(@":Strikethrough").strikethrough(^(id<SJUTDecoration>  _Nonnull make) {
        make.style = NSUnderlineStyleSingle;
        make.color = UIColor.greenColor;
    });

    make.append(@"n");
    make.append(@":BackgroundColor").backgroundColor(UIColor.greenColor);

    make.append(@"n");
    make.append(@":Kern").kern(6);

    make.append(@"n");
    make.append(@":Shadow").shadow(^(NSShadow * _Nonnull make) {
        make.shadowColor = [UIColor redColor];
        make.shadowOffset = CGSizeMake(0, 1);
        make.shadowBlurRadius = 5;
    });

    make.append(@"n");
    make.append(@":Stroke").stroke(^(id<SJUTStroke>  _Nonnull make) {
        make.color = [UIColor greenColor];
        make.width = 1;
    });

    make.append(@"n");
    make.append(@"oOo").font([UIFont boldSystemFontOfSize:25]).alignment(NSTextAlignmentCenter);

    make.append(@"n");
    make.append(@"Regular Expression").backgroundColor([UIColor greenColor]);
    make.regex(@"Regular").update(^(id<SJUTAttributesProtocol>  _Nonnull make) {
        make.font([UIFont boldSystemFontOfSize:25]).textColor(UIColor.purpleColor);
    });

    make.regex(@"ss").replaceWithString(@"SS").backgroundColor([UIColor greenColor]);
    make.regex(@"on").replaceWithText(^(id<SJUIKitTextMakerProtocol>  _Nonnull make) {
        make.append(@"ON😆").textColor([UIColor redColor]).backgroundColor([UIColor greenColor]).font([UIFont boldSystemFontOfSize:30]);
    });
 }];

Contact

Latest podspec

{
    "name": "SJAttributesStringMaker",
    "version": "2.1.0",
    "summary": "u5bccu6587u672cu7f16u8f91u5de5u5382.",
    "description": "u5bccu6587u672cu7f16u8f91u5de5u5382, u4e3au7701u53bbu7e41u7410u7684u7f16u8f91u4ee3u7801, u6240u4ee5u91c7u7528u4e86u94feu5f0fu8bedu6cd5u53bbu521bu5efau4e00u4e2aAttributedString.",
    "homepage": "https://github.com/changsanjiang/SJAttributesFactory",
    "license": {
        "type": "MIT",
        "file": "LICENSE.md"
    },
    "authors": {
        "SanJiang": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/changsanjiang/SJAttributesFactory.git",
        "tag": "v2.1.0"
    },
    "source_files": "SJAttributesStringMaker/*.swift",
    "frameworks": "UIKit",
    "subspecs": [
        {
            "name": "Deprecated",
            "source_files": "SJAttributesStringMaker/Deprecated/*.swift"
        }
    ]
}

Pin It on Pinterest

Share This