使用 Swift 编写的自定义视图,允许您显示垂直的状态进度。当您在显示下一步操作的同时展示用户当前状态时非常方便。
Swift 2.2+
将其添加到 Storyboard/Code 中的子视图中。
override func viewDidLoad() {
super.viewDidLoad()
self.statesView.dataSource = self
self.statesView.circleMaxSize = 80
self.statesView.backgroundColor = UIColor.whiteColor()
...
}
然后使用 CircularStatesViewDataSource 协议
extension ViewController: CircularStatesViewDataSource {
func numberOfStatesInCricularStatesView(cricularStatesView: CircularStatesView) -> Int {
return 4
}
func cricularStatesView(cricularStatesView: CircularStatesView, isStateActiveAtIndex index: Int) -> Bool {
return index <= self.myModelState
}
...
}
// The DataSource
public weak var dataSource: CircularStatesViewDataSource?
/// The number of states in view
public var numberOfStates: Int { get }
/// The circle's active state fill color
public var circleActiveColor: UIColor
/// The circle's in-active state fill color
public var circleInactiveColor: UIColor
/// The circle's border color
public var circleBorderColor: UIColor
/// The width of the border
public var circleBorderWidth: CGFloat
/// The circle size (diameter) is calculated using the view height and seperatorLength
public var circleSize: CGFloat { get }
/// Overrides the circle size calculation with a pre defined max size, min(calculatedSize(), circleMaxSize)
public var circleMaxSize: CGFloat?
/// The length of the seperator line between each circle state
public var seperatorLength: CGFloat
/// The line seperator color
public var seperatorColor: UIColor
/// The line seperator width
public var seperatorWidth: CGFloat
/// The states title font
public var stateTitleFont: UIFont
/// The color for the active title text label
public var titleLabelActiveTextColor: UIColor
/// The color for the inactive title text label
public var titleLabelInactiveTextColor: UIColor
/// The index for the state with activity indicator
public var indexForStateWithActivityIndicator: Int?
/// The color for the activity indicator
public var stateActivityIndicatorColor: UIColor
DataSource reloadData
func reloadData()
数据源协议
public protocol CircularStatesViewDataSource: class {
/**
Return the number of states in the view
- parameter circularStatesView: The CircularStatesView
- returns: The number of states
*/
func numberOfStatesInCircularStatesView(circularStatesView: CircularStatesView) -> Int
/**
Return whether the state at index is active or inactive
- parameter circularStatesView: The CircularStatesView
- parameter index: The state index
- returns: true/false for active/inactive state
*/
func circularStatesView(circularStatesView: CircularStatesView, isStateActiveAtIndex index: Int) -> Bool
/**
Return the title string for the state, this title we'll be displayed along side the state
- parameter circularStatesView: The CircularStatesView
- parameter index: The state index
- returns: title string or nil if you don't need a title for the specific state
*/
func circularStatesView(circularStatesView: CircularStatesView, titleForStateAtIndex index: Int) -> String?
/**
Return image icon for active state, this icon will be shown in the circle center
- parameter circularStatesView: The CircularStatesView
- parameter index: The state index
- returns: UIImage for the image icon or nil if you don't want to show an icon
*/
func circularStatesView(circularStatesView: CircularStatesView, imageIconForActiveStateAtIndex index: Int) -> UIImage?
/**
Return image icon for inactive state, this icon will be shown in the circle center
- parameter circularStatesView: The CircularStatesView
- parameter index: The state index
- returns: UIImage for the image icon or nil if you don't want to show an icon
*/
func circularStatesView(circularStatesView: CircularStatesView, imageIconForInActiveStateAtIndex index: Int) -> UIImage?
}
CircularStatesView 由 Or Elmaliah 所有并维护。您可以在 Twitter 上关注我 @OrElm。
版权所有 © 2016 Or Elmaliah
以下条件下,授予任何获取此软件及其相关文档文件(“软件”)副本的个人免费使用软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并准许获得软件副本的个人进行此类使用:
应包含上述版权声明和本许可声明在内的软件的所有副本或主要内容。
本软件按“原样”提供,不提供任何形式的质量保证,无论是明示还是暗示,包括但不限于对适销性、特定用途适用性和非侵权的保证。在任何情况下,作者或版权所有者都不得对任何索赔、损害或其他责任承担责任,无论其性质为何,也不论是否因合同、侵权或其他原因而引起,并与其产生的软件或软件的使用、销售或其他施加有任何联系。