FWSegmentedControl 2.3.3

FWSegmentedControl 2.3.3

Maintained by xfg.



  • By
  • xfg

Platform  Language  License

支持pod导入:

use_frameworks!
pod 'FWSegmentedControl'
注意:
1、如出现 [!] Unable to find a specification for 'FWSegmentedControl' 错误 或 看不到最新的版本,
  可执行 pod repo update 命令更新一下本地pod仓库。
2、use_frameworks! 的使用:
(1)纯OC项目中,通过cocoapods导入OC库时,一般都不使用use_frameworks!
(2)纯swift项目中,通过cocoapods导入swift库时,必须使用use_frameworks!
(3)只要是通过cocoapods导入swift库时,都必须使用use_frameworks!
(4)使用动态链接库dynamic frameworks时,必须使用use_frameworks!

可设置参数:

/// 标题
@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)

/// 类初始化方法
///
/// - 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)) 

效果:

注意点:

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

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

更新记录:

• v2.1.7:

  • 添加:sectionSelectedImageDict,使得在一个FWSegmentedControl中支持图片+文字、图片、文字的混排形式;
  • 选中标识符可设置圆角,默认圆角值为:1.5f;
  • 新增已经选中了某个index后再次点击的回调:SCIndexSecondClickedBlock;
  • 修复segmentEdgeInset位置右移的问题;
  • 更多细节调整;

结尾语:

  • 使用过程中发现bug请issues或加入FW问题反馈群:670698309(此群只接受FW相关组件问题);
  • 有新的需求欢迎提出;