SMSegmentView

Custom segmentedControl for iOS written in Swift. Supports vertical layout. Support both image and text. Highly customisable.

  • 所有者: sima-11/SMSegmentView
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

SMSegmentView Description

  • Custom segmented control for iOS.
  • Written in Swift.
  • Support both images and text.
  • Support vertically organise segments.
  • More customisible than UISegmentedControl and easy to expand (e.g. styling).

For CocoaPods User

Add pod 'SMSegmentView', '~> [VERSION]' to Podfile.

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:, dividerColour:, dividerWidth:, segmentAppearance:) to make it look more customised.
The parameter segmentAppearance: reads a SMSegmentAppearance instance. You can find what attributes it supports in SMSegmentAppearance class.

E.g.:

let appearance = SMSegmentAppearance()
appearance.segmentOnSelectionColour = UIColor(red: 245.0/255.0, green: 174.0/255.0, blue: 63.0/255.0, alpha: 1.0)
appearance.segmentOffSelectionColour = UIColor.whiteColor()
appearance.titleOnSelectionFont = UIFont.systemFontOfSize(12.0)
appearance.titleOffSelectionFont = UIFont.systemFontOfSize(12.0)
appearance.contentVerticalMargin = 10.0

let segmentView = SMSegmentView(frame: SomeFrame, dividerColour: UIColor(white: 0.95, alpha: 0.3), dividerWidth: 1.0, segmentAppearance: appearance)

Step 3

Add action for UIControlEvents.ValueChanged, and implement the action method.

E.g. segmentView.addTarget(self, action: #selector(YourViewController.selectSegmentInSegmentView(_:)), forControlEvents: .ValueChanged)

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 assign an integer to selectedSegmentIndex.

Support Vertical Mode

You can organise all segments vertically by setting the organiseMode as .Vertical. It is set to .Horizontal by default.

E.g. segmentView.organiseMode = .Vertical

More Info

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

Screenshots

主要指標

概覽
名稱與所有者sima-11/SMSegmentView
主編程語言Swift
編程語言Swift (語言數: 3)
平台
許可證MIT License
所有者活动
創建於2015-01-09 14:07:49
推送於2019-10-31 13:16:36
最后一次提交2018-03-13 10:46:37
發布數6
最新版本名稱1.4 (發布於 )
第一版名稱v1.0 (發布於 )
用户参与
星數619
關注者數17
派生數103
提交數74
已啟用問題?
問題數27
打開的問題數6
拉請求數5
打開的拉請求數10
關閉的拉請求數4
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?