Code Monkey home page Code Monkey logo

sjattributesfactory's Introduction

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

sjattributesfactory's People

Contributors

changsanjiang avatar

Watchers

James Cloos avatar

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.