Giter VIP home page Giter VIP logo

xmsegmentedcontrol's Introduction

XMSegmentedControl

Version License Platform

Overview

XMSegmentedControl is a customizable segmented control. It allows using Text, Icons, or a combination of Icons and Text as the segments.

Screenshot

Requirements

  • iOS 8+

Installation

You can install XMSegmentedControl manually by simply copying XMSegmentedControl.swift into your project's workspace.

XMSegmentedControl is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "XMSegmentedControl"

Usage

  • Import XMSegmentedControl into your project.
import XMSegmentedControl
  • Use the Storyboard and drag a UIView.
  • Select the view and under the Identity Inspector select XMSegmentedControl under class.
  • Conform to the XMSegmentedControlDelegate protocol by implementing func xmSegmentedControl(xmSegmentedControl: XMSegmentedControl, selectedSegment: Int) to receive notifications on which segment was selected.
func xmSegmentedControl(xmSegmentedControl: XMSegmentedControl, selectedSegment: Int) {
print("SegmentedControl Selected Segment: \(selectedSegment)")
}

Alternatively, create a XMSegmentedControl from code.

Text Only Segmented Control

The example below creates a text-only segmented control.

let segmentedControl3 = XMSegmentedControl(frame: CGRect(x: 0, y: 224, width: self.view.frame.width, height: 44), segmentTitle: ["Hello", "World", "Three"], selectedItemHighlightStyle: XMSelectedItemHighlightStyle.topEdge)

segmentedControl3.backgroundColor = UIColor(red: 22/255, green: 150/255, blue: 122/255, alpha: 1)
segmentedControl3.highlightColor = UIColor(red: 25/255, green: 180/255, blue: 145/255, alpha: 1)
segmentedControl3.tint = UIColor.white
segmentedControl3.highlightTint = UIColor.black

self.view.addSubview(segmentedControl3)

TextOnly

Icon Only Segmented Control

The example below creates an icon-only segmented control.

let icons1:[UIImage] = [UIImage(named: "icon1")!, UIImage(named: "icon2")!, UIImage(named: "icon3")!, UIImage(named: "icon4")!, UIImage(named: "icon5")!, UIImage(named: "icon6")!]

let segmentedControl4 = XMSegmentedControl(frame: CGRect(x: 0, y: 274, width: self.view.frame.width, height: 44), segmentIcon: icons1, selectedItemHighlightStyle: XMSelectedItemHighlightStyle.background)

segmentedControl4.backgroundColor = UIColor(red: 128/255, green: 59/255, blue: 159/255, alpha: 1)
segmentedControl4.highlightColor = UIColor(red: 144/255, green: 79/255, blue: 173/255, alpha: 1)
segmentedControl4.tint = UIColor.white

self.view.addSubview(segmentedControl4)

IconOnly

Horizontal Icon + Text Segmented Control

The example below creates a horizontal Icon + Text segmented control.

let backgroundColor = UIColor(red: 205/255, green: 74/255, blue: 1/255, alpha: 1)
let highlightColor = UIColor(red: 226/255, green: 114/255, blue: 31/255, alpha: 1)

let titles = ["Hello", "World", "Two"]
let icons = [UIImage(named: "icon1")!, UIImage(named: "icon2")!, UIImage(named: "icon3")!]
let frame = CGRect(x: 0, y: 114, width: self.view.frame.width, height: 44)

let segmentedControl2 = XMSegmentedControl(frame: frame, segmentContent: (titles, icons), selectedItemHighlightStyle: XMSelectedItemHighlightStyle.bottomEdge)

segmentedControl2.backgroundColor = backgroundColor
segmentedControl2.highlightColor = highlightColor
segmentedControl2.tint = UIColor.white
segmentedControl2.highlightTint = UIColor.black

self.view.addSubview(segmentedControl2)

IconText

Vertical Icon + Text Segmented Control

The example below creates a vertical Icon + Text segmented control.

let backgroundColor8 = UIColor(red: 160/255, green: 74/255, blue: 1/255, alpha: 1)
let highlightColor8 = UIColor(red: 181/255, green: 114/255, blue: 31/255, alpha: 1)

let titles8 = ["Hello", "World", "Eight"]
let icons = [UIImage(named: "icon1")!, UIImage(named: "icon2")!, UIImage(named: "icon3")!]
        
let segmentedControl8 = XMSegmentedControl(frame: CGRect(x: 0, y: 164, width: self.view.frame.width, height: 54), verticalSegmentContent: (titles8, icons), selectedItemHighlightStyle: XMSelectedItemHighlightStyle.bottomEdge)

segmentedControl8.backgroundColor = backgroundColor8
segmentedControl8.highlightColor = highlightColor8
segmentedControl8.tint = UIColor.white
segmentedControl8.highlightTint = UIColor.black

self.view.addSubview(segmentedControl8)

IconText

For more examples see the Example Project provided.

Example Project

To run the example project, clone the repo, and run pod install from the Example directory first. Icons in the example project are provided by http://icons8.com

Author

Xavier Merino, [email protected]

License

XMSegmentedControl is available under the MIT license. See the LICENSE file for more info.

xmsegmentedcontrol's People

Contributors

caotrido avatar eluss avatar ffchung avatar haaakon avatar jessearmand avatar ostapkuzyk avatar xaviermerino avatar

Watchers

 avatar  avatar  avatar

Forkers

gobike

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.