Latest 1.0.6
Homepage https://github.com/imwangxuesen/JsenSegment
License MIT
Platforms ios 8.0, requires ARC
Authors

A custom segment that can custom normal & selected text and image or backgroundColor.Support Swift4.0 and later

GIF

GIF

Requirements

  • iOS 8.0+
  • Swift 4.0+

Communication

• If you found a bug,open an issue.

• If you have a feature request, open an issue.

• If you want to contribute, submit a pull request.

Installation

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

pod 'JsenSegment'

Usage


import JsenSegment.Swift

/// initial
/// 初始化
let segment = JsenSegment.init(frame: CGRect.init(x: 0, y: 50, width: self.view.bounds.width, height: 50))

/// title
/// 正常状态时 title 文字
let title = NSAttributedString.init(string: "Click Me",
                                attributes: [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 15) ,NSAttributedStringKey.foregroundColor : UIColor.blue])

/// selected title
/// 选中时 title 文字
let selectedTitle = NSAttributedString.init(string: "Selected Item",
                                        attributes: [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 17) ,NSAttributedStringKey.foregroundColor : UIColor.red])

/// itemAttribute
/// item属性
let itemAttribute = JsenSegmentItemAttribute.init(title: title,
                                        backgroundColor: UIColor.yellow,
                                                   type: .text, imageName: nil,
                                          selectedTitle: selectedTitle,
                                selectedBackgroundColor: UIColor.groupTableViewBackground,
                                           selectedType: .text, selectedImageName: nil)

/// itemAttribute2
let itemAttribute2 = JsenSegmentItemAttribute(title: title,
                                    backgroundColor: UIColor.yellow,
                                      selectedTitle: selectedTitle,
                            selectedBackgroundColor: UIColor.groupTableViewBackground)

/// indicatorAttribute
/// 滑块指示器属性
let indicatorAttribute = JsenSegmentIndicatorAttribute.init(with:UIColor.ufGreenColor(),
                                             type: .slider,
                                           height: 5.0,
                                                                    position: .bottom)

/// config
/// 配置方法
segment.config(with: indicatorAttribute,
         dataSource: [itemAttribute,itemAttribute2,itemAttribute,itemAttribute2],
      selectedIndex: 0 ,
            panAble: true) { (index) in
    /// item index 变化回调
    print("segment current index:" + String(index))
}

self.view.addSubview(segment)

Latest podspec

{
    "name": "JsenSegment",
    "version": "1.0.6",
    "summary": "A custom segment that can custom normal & selected text and image or backgroundColor.Support Swift4.0 and later",
    "homepage": "https://github.com/imwangxuesen/JsenSegment",
    "license": "MIT",
    "authors": {
        "WangXuesen": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/imwangxuesen/JsenSegment.git",
        "tag": "1.0.6"
    },
    "source_files": "JsenSegment/*.{swift,bundle}",
    "requires_arc": true,
    "resources": "JsenSegment/JsenSegment.bundle",
    "pushed_with_swift_version": "4.0.0"
}

Pin It on Pinterest

Share This