MNSwitchi

master

mednoor/MNSwitchi

MNSwitchi

Custom animated segmented control written in Swift 5.2

Twitter: @a_moha

Requirements

  • Xcode 11.4
  • iOS 11.x+
  • Swift 5.2

Installation

Swift Package Manager

.package(
    url: "https://github.com/mednoor/MNSwitchi.git",
    from: "0.2.0"
)

Usage

Import MNSwitchi module

import MNSwitchi

Init

You can initialize a MNSwitchi instance from code:

let switchiView = MNSwitchiView(frame: CGRect(x: 0, y: 0, width: 240, height: 36))
view.addSubview(switchiView)

Setup MNSwitchi

switchiView.render(
	content: MNSwitchiContent,
	appearance: MNSwitchiAppearance,
	options: MNSwitchiOptions
)

Configuring Content

In order to set items you need to pass a tuple of type MNSwitchiContent:

let items: MNSwitchiContent = (first: "First", second: "Second")

Appearance

In order to set the styling you need to pass an object of type MNSwitchiAppearance:

let appearance = MNSwitchiAppearance(backgroundColor: UIColor,
                                     cornersRounded: Bool,
                                     selectedViewBackgroundColor: UIColor,
                                     states: MNSwitchiStates)

then create an instance of MNSwitchiStates:

let states = MNSwitchiStates(

default: MNSwitchiStates.MNSwitchiState(textColor: UIColor,
                                        titleFont: UIFont),

selected: MNSwitchiStates.MNSwitchiState(textColor: UIColor,
                                         titleFont: UIFont),
            
highlighted: MNSwitchiStates.MNSwitchiState(textColor: UIColor,
                                            titleFont: UIFont)
)

Customization

MNSwitchi can be customized by passing an instance of MNSwitchiOptions:

let options = MNSwitchiOptions(defaultSelectedItem: Int,
                               enableAnimation: Bool)

Handling callback

switchiView.switchedTo = { index in
    print("Selected item at: \(index)")
}

Description

  • Swift Tools 5.2.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 22:28:09 GMT-0900 (Hawaii-Aleutian Daylight Time)