Giter Site home page Giter Site logo

beichenglangzi / tosegmentedcontrol Goto Github PK

View Code? Open in Web Editor NEW

This project forked from timoliver/tosegmentedcontrol

0.0 1.0 0.0 434 KB

A segmented control in the style of iOS 13 compatible with previous versions of iOS.

License: MIT License

Objective-C 98.31% Ruby 0.64% Swift 1.05%

tosegmentedcontrol's Introduction

TOSegmentedControl

TOSegmentedControl

CI Version Carthage compatible GitHub license Platform PayPal Twitch

As part of the visual improvements featured in iOS 13, UISegmentedControl was completely redesigned, featuring a much rounder, cleaner, and slightly more skeuomorphic appearance.

TOSegmentedControl is a subclass of of UIControl that completely re-implements the look and feel of the new UISegmentedControl component, allowing developers to adopt its look even in previous versions of iOS they support.

Features

  • Recreates the new look of UISegmentedControl, making it available on previous versions of iOS.
  • Supports both text and images as segment types.
  • Support for @IBDesignable and @IBInspectable.
  • Configurable to dynamically add or remove items after its creation.
  • Written in Objective-C, but provides full compatibility with Swift.
  • Provides both a block, or UIControlEvents to receive when the control is tapped.
  • Light and dark mode support for iOS 13.
  • A reversible mode where tapping the same item twice flips its direction.

Sample Code

TOSegmentedControl has been written to follow the interface of UISegmentedControl as closely as possible. This should make it very intuitive to work with.

Swift

In Swift, the class is renamed to SegmentedControl. Creating a new instance is very similar to UISegmentedControl.

// Create a new instance
let segmentedControl = SegmentedControl(items: ["First", "Second", "Third"])

// Add a closure that will be called each time the selected segment changes
segmentedControlsegmentTappedHandler = { segmentIndex, reversed in
   print("Segment \(segmentIndex) was tapped!")
}

// Add a new item to the end
segmentedControl.addSegment(withTitle: "Fourth")

// Insert a new item at the beginning
segmentedControl.insertSegment(withTitle: "Zero", at: 0)

// Remove all segments
segmentedControl.removeAllSegments()

Objective-C

NSArray *items = @[@"First", @"Second", @"Third"];

// Create a new instance
TOSegmentedControl *segmentedControl = [[TOSegmentedControl alloc] initWithItems:items]];

// Add a block that will be called each time the selected segment changes
segmentedControl.segmentTappedHandler = ^(NSInteger index, BOOL reversed) {
    NSLog(@"Segment %d was tapped!", index);
};

// Add a new item to the end
[segmentedControl addSegmentWithTitle:@"Fourth"];

// Insert a new item at the beginning
[segmentedControl insertSegmentWithTitle:@"Zero" atIndex:0];

// Remove all segments
[segmentedControl removeAllSegments];

System Requirements

iOS 9.0 or above

Installation

CocoaPods

Add the following to your Podfile:

pod 'TOSegmentedControl'
Carthage
  1. Add the following to your Cartfile:
github "TimOliver/TOSegmentedControl"
  1. Run carthage update

  2. From the Carthage/Build folder, import the TOSegmentedControl.framework.

  3. Follow the remaining steps on Getting Started with Carthage to finish integrating the framework.

Manual Installation

All of the necessary source files located in the TOSegmentedControl folder. Simply drag that folder into your Xcode project.

Credits

TOSegmentedControl was created by Tim Oliver as a component for iComics.

iOS device mockup by Pixeden.

License

TOSegmentedControl is available under the MIT license. Please see the LICENSE file for more information. analytics

tosegmentedcontrol's People

Contributors

timoliver avatar ppamorim avatar xd-ci avatar ahmed-elkollaly 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.