Code Monkey home page Code Monkey logo

smsegmentview's Introduction

SMSegmentView Description

  • Custom segmented control for iOS 7 and above.
  • Written in Swift.
  • Support both images and text.
  • Support vertically organise segments
  • More customisible than UISegmentedControl and easier to expand with new style.

How To Use

Step 1

Drag SMSegmentView.swift and SMSegment.swift into your Xcode project.

Step 2

Initialise SMSegmentView: You can simply use SMSegmentView(frame:) to initialise your segment view by using the default properties. But mostly, you may want to use SMSegmentView(frame: seperatorColour: seperatorWidth: segmentProperties:) to make it look more customised. The parameter segmentProperties: reads a Dictionary<String, AnyObject> value. You can find what key it supports on the top of SMSegmentView file.

E.g.:

var segmentView = SMSegmentView(frame: CGRect(x: 10.0, y: 50.0, width: 300.0, height: 40.0), seperatorColour: UIColor.blueColor(), seperatorWidth: 1.0, segmentProperties: [keySegmentTitleFont: UIFont.systemFontOfSize(12.0), keySegmentOnSelectionColour: UIColor.blackColor(), keySegmentOffSelectionColour: UIColor.greenColor(), keyContentVerticalMargin: 5.0])

Step 3

Assign delegate for the instance of SMSegmentView.

E.g. segmentView.delegate = self

Step 4

Add segments to your segment view.

E.g.:

segmentView.addSegmentWithTitle("Segment 1", onSelectionImage: UIImage(named: "target_light"), offSelectionImage: UIImage(named: "target"))
segmentView.addSegmentWithTitle("Segment 2", onSelectionImage: UIImage(named: "handbag_light"), offSelectionImage: UIImage(named: "handbag"))
segmentView.addSegmentWithTitle("Segment 3", onSelectionImage: UIImage(named: "globe_light"), offSelectionImage: UIImage(named: "globe"))

Optional Step

You can programmatically select/deselect a segment by calling selectSegmentAtIndex(index: Int).

Support Vertical Mode

You can organise all segments vertically by setting the segmentMode as .SegmentOrganiseVertical. It is set to .SegmentOrganiseHorizontal by default.

E.g. segmentView.segmentMode = .SegmentOrganiseVertical

More Info

The framework comes with a sample project for you. Besides, this tutorial may give you some idea how to expand this framework a little bit.

Screenshots

smsegmentview's People

Contributors

sima-11 avatar

Watchers

 avatar  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.