Giter VIP home page Giter VIP logo

zjswitch's Introduction

ZJSwitch

ZJSwitch is a simple implmentation for swtich control that similar to UISwitch.

ZJSwitch can add text on control for on of off status.

How to use it

    ZJSwitch *switch0 = nil;
    UIColor *onTintColor = nil;
    UIColor *tintColor = nil;
    UIColor *thumbTintColor = nil;
    ZJSwitchStyle style = ZJSwitchStyleBorder;
    NSString *onText = nil;
    NSString *offText = nil;
    
    for (NSInteger i = 0; i < 13; i++) {
        style = i % 2 == 0 ? ZJSwitchStyleBorder : ZJSwitchStyleNoBorder;
        
        srand((unsigned int)i + 1);
        onTintColor = [UIColor colorWithRed:(rand() % 256) / 255.0
                                      green:(rand() % 256) / 255.0
                                       blue:(rand() % 256) / 255.0
                                      alpha:1.0];
        
        srand((unsigned int)(i + 1) * 2);
        tintColor = [UIColor colorWithRed:(rand() % 256) / 255.0
                                    green:(rand() % 256) / 255.0
                                     blue:(rand() % 256) / 255.0
                                    alpha:1.0];
        
        srand((unsigned int)(i + 1) * 3);
        thumbTintColor = [UIColor colorWithRed:(rand() % 256) / 255.0
                                         green:(rand() % 256) / 255.0
                                          blue:(rand() % 256) / 255.0
                                         alpha:1.0];
        
        onText = (i % 3 == 0) ? @"ON" : nil;
        offText = (i % 3 == 0) ? @"OFF" : nil;
        
        switch0 = [[ZJSwitch alloc] initWithFrame:CGRectMake(20, i * (10 + 31) + 40, 60, 31)];
        switch0.style = style;
        switch0.onTintColor = onTintColor;
        switch0.tintColor = tintColor;
        switch0.thumbTintColor = thumbTintColor;
        switch0.onText = onText;
        switch0.offText = offText;
        [switch0 addTarget:self action:@selector(handleSwitchEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:switch0];
        
        switch0 = [[ZJSwitch alloc] initWithFrame:CGRectMake(180, i * (10 + 31) + 40, 60, 31)];
        switch0.style = style;
        switch0.onTintColor = onTintColor;
        switch0.tintColor = tintColor;
        switch0.thumbTintColor = thumbTintColor;
        switch0.onText = onText;
        switch0.offText = offText;
        [switch0 addTarget:self action:@selector(handleSwitchEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:switch0];
        
        switch0.on = YES;
    }

How does it look like

ZJSwitch

zjswitch's People

Contributors

jameszjhe avatar

Watchers

James Cloos avatar neil 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.