Latest 2.1.5
Homepage https://github.com/choiceyou/FWSegmentedControl
License MIT
Platforms ios 8.0
Authors

IOS之分段控制器 — OC/Swift4.0

Platform 
Language 
License

支持pod导入:

pod 'FWSegmentedControl'
注意:如出现 Unable to find a specification for 'FWSegmentedControl' 错误,可执行 pod repo update 命令。

可设置参数:

“`参数
/// 标题
@objc public var sectionTitleArray: [String]?
/// 图片
@objc public var sectionImageArray: [UIImage]?
/// 选中图片
@objc public var sectionSelectedImageArray: [UIImage]?

/// segment类型
@objc public var scType = SCType.text
/// segment宽度
@objc public var scWidthStyle = SCWidthStyle.fixed
/// 图片相对于文字的位置
@objc public var scImagePosition: SCImagePosition = .leftOfText
/// 选中标识符类型
@objc public var scSelectionIndicatorStyle = SCSelectionIndicatorStyle.contentWidthStripe
/// 选中标识符位置
@objc public var scSelectionIndicatorLocation = SCSelectionIndicatorLocation.down
/// 边框类型
public var scBorderType: SCBorderType = .none

/// 选中标识符高度,注意:self.scSelectionIndicatorStyle == .box || self.scSelectionIndicatorStyle == .none 时无效
@objc public var selectionIndicatorHeight: CGFloat = 3.0
/// 选中标识符,当 SCSelectionIndicatorLocation == up 时,底部edge无效;反之,顶部edge无效;
@objc public var selectionIndicatorEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)
/// 选中标识符颜色
@objc public var selectionIndicatorColor = UIColor.red
@objc public var selectionIndicatorBoxColor = UIColor.gray

/// 滑动或者选中回调
@objc public var indexChangeBlock: SCIndexChangeBlock?
/// 标题NSAttributedString回调
@objc public var titleFormatterBlock: SCTitleFormatterBlock?
/// segment的Inset属性
@objc public var segmentEdgeInset = UIEdgeInsetsMake(0, 5, 0, 5)
@objc public var enlargeEdgeInset = UIEdgeInsetsMake(0, 0, 0, 0)

/// 未选中的标题属性
@objc public var titleTextAttributes: [NSAttributedStringKey: Any]?
/// 选中的标题属性
@objc public var selectedTitleTextAttributes: [NSAttributedStringKey: Any]?

/// 是否可以拖动
@objc public var userDraggable = true
/// 是否可以点击
@objc public var touchEnabled = true

/// segment的边框颜色
@objc public var segmentBorderColor = UIColor.black
/// segment的边框大小
@objc public var segmentBorderWidth: CGFloat = 1.0

/// 选中或者滑动时是否需要动画
@objc public var shouldAnimateUserSelection = true

/// 选中标识符为箭头的宽度
@objc public var arrowWidth: CGFloat = 6.0

/// 选中表示符为box时的opacity值
@objc public var selectionIndicatorBoxOpacity: CGFloat = 0.2

/// segment之间的间隔竖线的宽度
@objc public var verticalDividerWidth: CGFloat = 1.0
/// 是否需要segment之间的间隔竖线
@objc public var verticalDividerEnabled = false
/// segment之间的间隔竖线的颜色
@objc public var verticalDividerColor = UIColor.black

/// 选中标识符滑动的时间
@objc public var indicatorAnimatedTimes: CFTimeInterval = 0.15

/// self.scType == .textImages 时,文字、图片的间隔
@objc public var textImageSpacing: CGFloat = 4.0

/// 选中项的下标
@objc public var selectedSegmentIndex: Int = 0


## 简单使用:(注:可下载demo具体查看,分别有OC、Swift的demo)

```swift
/// 类初始化方法
///
/// - Parameters:
///   - scType: segment类型
///   - sectionTitleArray: 标题,可传nil,后续再设置
///   - sectionImageArray: 图片,可传nil,后续再设置
///   - sectionSelectedImageArray: 选中图片,可传nil,后续再设置
///   - frame: frame
@objc open class func segmentedWith(scType: SCType,
                              scWidthStyle: SCWidthStyle,
                         sectionTitleArray: [String]?,
                         sectionImageArray: [UIImage]?,
                 sectionSelectedImageArray: [UIImage]?,
                                     frame: CGRect) -> FWSegmentedControl

OC:

[FWSegmentedControl segmentedWithScType: SCTypeText
                           scWidthStyle: SCWidthStyleDynamicFixedSuper
                      sectionTitleArray: @[@"关注", @"游戏", @"附近"]
                      sectionImageArray: nil 
              sectionSelectedImageArray: nil
                                  frame: CGRectMake(0, 40, self.view.frame.size.width, 50)];

Swift:

FWSegmentedControl.segmentedWith(scType: SCType.text,
                           scWidthStyle: SCWidthStyle.fixed,
                      sectionTitleArray: ["关注", "游戏", "附近"],
                      sectionImageArray: nil,
              sectionSelectedImageArray: nil,
                                  frame: CGRect(x: 0, y: 40, width: Int(UIScreen.main.bounds.width), height: 50)) 

效果:

FWSegmentedControl
FWSegmentedControl

注意点:

一、本UI库是用Swift4.0编写的,所以安装或者拖入文件后需要把对应的Swift设置为4.0版本:
(1)pod安装方式:FWSegmentedControl
(2)文件拖入方式:Targets –> Build Setting 做相同的设置

二、如果是文件拖入方式,需要设置OC、Swift混编等,相关问题网上有很多解答,我这边就不再重复了

结尾语:

  • 使用过程中有任何问题或者新的需求都可以issues我哦;
  • 欢迎关注本人更多的UI库,谢谢;

Latest podspec

{
    "name": "FWSegmentedControl",
    "version": "2.1.5",
    "summary": "u6ed1u52a8u5206u6bb5u63a7u5236uff0cu591au6837u5f0fu3001u7075u6d3bu3001u4fbfu5229u662fu5176u6700u5927u7684u4f18u52bfu3002",
    "description": "FWSegmentedControlu517cu5bb9OCuff0cu501fu9274u4e86u524du8f88u9879u76eeuff1aHMSegmentedControluff0cu5728u6b64u975eu5e38u611fu8c22u524du8f88u7684u5206u4eab",
    "homepage": "https://github.com/choiceyou/FWSegmentedControl",
    "license": "MIT",
    "authors": {
        "xfg": "[email protected]"
    },
    "swift_version": "4.0",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/choiceyou/FWSegmentedControl.git",
        "tag": "2.1.5"
    },
    "source_files": "FWSegmentedControl/FWSegmentedControl/FWSegmentedControl/*.swift"
}

Pin It on Pinterest

Share This