BadgeSegmentControl 2.0

BadgeSegmentControl 2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2017年9月
SwiftSwift 版本4.0
SPM支持 SPM

Florian Gabach 维护。



  • Florian Gabach

特性安装使用自定义许可证

带图像、文本和徽章的精美分段控制!高度可定制的。

Screen

特性

  • [x] 只有文本的分段控制
  • [x] 有图像和文本的分段控制
  • [x] 只有图像的分段控制
  • [x] 显示徽章

待办事项(请自由提交 PR)

  • [ ] 单元测试和 UI 测试

要求

  • Xcode 8
  • iOS 9.0+ 目标部署
  • Swift 3 项目
  • 依赖 SwiftBadge

安装

  • 要使用 CocoaPods 将 BadgeSegmentControl 集成到您的 Xcode 项目中,请在 Podfile 中指定它
pod "BadgeSegmentControl"
  • 要使用 Carthage 将 BadgeSegmentControl 集成到您的 Xcode 项目中,请在 Cartfile 中指定它
github "terflogag/BadgeSegmentControl" 

使用

  • 导入库
import BadgeSegmentControl
  • 以编程方式显示分段控制
let padding: CGFloat = 50
let mySegmentControl = BadgeSegmentControl(frame: CGRect(x: padding / 2,
                                                         y: self.view.frame.height - (padding * 2),
                                                         width: self.view.frame.width - padding,
                                                         height: padding))
self.mySegmentControl?.segmentAppearance = SegmentControlAppearance.appearance()

// Add segments
self.mySegmentControl?.addSegmentWithTitle("First")
self.mySegmentControl?.addSegmentWithTitle("Second")
self.mySegmentControl?.addTarget(self,
                                 action: #selector(selectSegmentInSegmentView(segmentView:)),
                                 for: .valueChanged)

// Set segment with index 0 as selected by default
self.mySegmentControl?.selectedSegmentIndex = 0

// Add to subview
if let segmentControl = self.mySegmentControl {
    self.view.addSubview(segmentControl)
}
  • 监听变化
// Segment selector for .ValueChanged
func selectSegmentInSegmentView(segmentView: BadgeSegmentControl) {
    print("Select segment at index: \(segmentView.selectedSegmentIndex)")
}
  • 从Storyboard中

只需设置一个具有 BadgeSegmentControl 类的 UIView 并将其导出为 IBOutlet。

自定义

import BadgeSegmentControl

func appearance() -> BadgeSegmentControlAppearence {
    let appearance = BadgeSegmentControlAppearence()

    // Segment color 
    appearance.segmentOnSelectionColour = UIColor.white
    appearance.segmentOffSelectionColour = UIColor(red:1.00, green:0.62, blue:0.22, alpha:1.00)

    // Title font 
    appearance.titleOnSelectionFont = UIFont.systemFont(ofSize: 14)
    appearance.titleOffSelectionFont = UIFont.systemFont(ofSize: 14)

    // Title color 
    appearance.titleOnSelectionColour = UIColor(red:1.00, green:0.62, blue:0.22, alpha:1.00)
    appearance.titleOffSelectionColour = UIColor.white

    // Vertical margin 
    appearance.contentVerticalMargin = 10.0

    // Border style
    appearance.borderColor = UIColor.white
    appearance.cornerRadius = 5.0
    appearance.borderWidth = 2.0

    // Divider style
    appearance.dividerWidth = 1.0
    appearance.dividerColour = UIColor(white: 0.95, alpha: 0.3)

    return appearance
}

self.mySegmentControl?.segmentAppearance = self.appearance()

应用

一些已使用此分段控制的程序,如:

您的应用程序呢?如果您的应用程序也使用此库,请随意联系我或在 README 中提交 pull request。😁

作者

Florian Gabach, [email protected]

许可证

OpenSourceController 在MIT 许可证下可用。

如果您的应用程序使用此段控元件,请考虑在“版权/关于”部分添加许可证。您可以使用这个库来完成