目录
目录README.md

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)")
}
关于
39.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号