DateScrollPicker 1.1.0

DateScrollPicker 1.1.0

Alberto Aznar 维护。



DateScrollPicker  Logo

Version License Swift 5.0 Platform Twitter


您可以使用 DateScrollPicker 作为具有滚动日期视图的日历。这个集合有无限日期单元格,带有动画选择。使用 DateScrollPickerFormat 定制所有这些单元格,并用您自己的字体和颜色。看看下面的参数并学习如何使用。


DateScrollPicker

DateScrollPicker

  • 令人惊艳的无限日期选择器
  • 完全可定制
  • 动画选择
  • 显示每个日期的定制数据
  • 易于使用
  • 支持 iOS,用 Swift 5 编写

目录

安装

DateScrollPicker 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 并运行 pod install

pod 'DateScrollPicker'

然后您可以在需要时导入它

import DateScrollPicker

用法

在示例中,您将看到一些日期滚动选择器视图的不同格式,这些格式可用于您的项目中。安装Pod后,请按照以下步骤操作。这很简单

在您的xib/Storyboard中添加UIView

在您希望放置DateScrollPicker视图的xib中添加一个UIView。然后您需要在视图中输入类名,您可以在界面构建器的身份检查器中更改此设置。请记住,在(类 & 模块)中输入DateScrollPicker

Screenshot 1

然后,将IBOutlet连接到您的UIViewController

@IBOutlet weak var dateScrollPicker: DateScrollPicker!

格式

您可以使用自己的参数格式化DateScrollPicker。在整个字段中使用它以获得相同的样式。查看默认值

var format = DateScrollPickerFormat()

/// Number of days
format.days = 5

/// Top label date format
format.topDateFormat = "EEE"

/// Top label font
format.topFont = UIFont.systemFont(ofSize: 10, weight: .regular)

/// Top label text color
format.topTextColor = UIColor.black

/// Top label selected text color
format.topTextSelectedColor = UIColor.white

/// Medium label date format
format.mediumDateFormat = "dd"

/// Medium label font
format.mediumFont = UIFont.systemFont(ofSize: 30, weight: .bold)

/// Medium label text color
format.mediumTextColor = UIColor.black

/// Medium label selected text color
format.mediumTextSelectedColor = UIColor.white

/// Bottom label date format
format.bottomDateFormat = "MMM"

/// Bottom label font
format.bottomFont = UIFont.systemFont(ofSize: 10, weight: .regular)

/// Bottom label text color
format.bottomTextColor = UIColor.black

/// Bottom label selected text color
format.bottomTextSelectedColor = UIColor.white

/// Day radius
format.dayRadius: CGFloat = 5

/// Day background color
format.dayBackgroundColor = UIColor.lightGray

/// Day background selected color
format.dayBackgroundSelectedColor = UIColor.darkGray

/// Selection animation
format.animatedSelection = true

/// Separator enabled
format.separatorEnabled = true

/// Separator top label date format
format.separatorTopDateFormat = "MMM"

/// Separator top label font
format.separatorTopFont = UIFont.systemFont(ofSize: 20, weight: .bold)

/// Separator top label text color
format.separatorTopTextColor = UIColor.black

/// Separator bottom label date format
format.separatorBottomDateFormat = "yyyy"

/// Separator bottom label font
format.separatorBottomFont = UIFont.systemFont(ofSize: 20, weight: .regular)

/// Separator bottom label text color
format.separatorBottomTextColor = UIColor.black

/// Separator background color
format.separatorBackgroundColor = UIColor.lightGray.withAlphaComponent(0.2)

/// Fade enabled
format.fadeEnabled = false

/// Animation scale factor
format.animationScaleFactor: CGFloat = 1.1

/// Animation scale factor
format.dayPadding: CGFloat = 5

/// Top margin data label
format.topMarginData: CGFloat = 10

/// Dot view size
format.dotWidth: CGFloat = 10

最终为DateScrollPicker分配格式是重要的

dateScrollPicker.format = format

实现数据源和委托

这是自定义DateScrollPicker的第一种方法:实现委托和数据源方法。这些方法处理最常见的用例。两者都是可选的。

dateScrollPicker.dataSource = self
dateScrollPicker.delegate = self

数据源

用于提供给ivat视图的数据。数据源必须遵循DateScrollPickerDataSource协议

// Returns custom attributed string for top label
func dateScrollPicker(_ dateScrollPicker: DateScrollPicker, topAttributedStringByDate date: Date) -> NSAttributedString?

// Returns custom attributed string for medium label
func dateScrollPicker(_ dateScrollPicker: DateScrollPicker, mediumAttributedStringByDate date: Date) -> NSAttributedString?

// Returns custom attributed string for bottom label
func dateScrollPicker(_ dateScrollPicker: DateScrollPicker, bottomAttributedStringByDate date: Date) -> NSAttributedString?

// Returns custom attributed string for separator top label
func dateScrollPicker(_ dateScrollPicker: DateScrollPicker, separatorTopAttributedStringByDate date: Date) -> NSAttributedString?

// Returns custom attributed string for separator bottom label
func dateScrollPicker(_ dateScrollPicker: DateScrollPicker, separatorBottomAttributedStringByDate date: Date) -> NSAttributedString?

// Returns custom attributed string for data label
func dateScrollPicker(_ dateScrollPicker: DateScrollPicker, dataAttributedStringByDate date: Date) -> NSAttributedString?

// Returns custom color for dot view
func dateScrollPicker(_ dateScrollPicker: DateScrollPicker, dotColorByDate date: Date) -> UIColor?

委托

为了在您的应用程序中添加更多功能,您必须实现DateScrollPickerDelegate 。这是负责管理选择行为的责任。

// Called when date is selected
func dateScrollPicker(_ dateScrollPicker: DateScrollPicker, didSelectDate date: Date)

更多

您还可以使用以下方法滚动到当前日期或其他日期。

// Scroll to current date
func selectToday(animated: Bool?)

// Scroll to date
func scrollToDate(date: Date, animated: Bool?)

使用 DateScrollPicker 的应用程序

如果您使用过 DateScrollPicker,我很乐意听取您的反馈,并且在这里展示您的应用程序!

DrinkGo

作者

Alberto Aznar, [email protected]

贡献

随时欢迎您提出想法进行合作💭,问题⁉️请求合并 pull.

  1. 分支!
  2. 创建您的特性分支:git checkout -b my-new-feature
  3. 提交您的更改:git commit -am 'Add some feature'
  4. 推送到分支:git push origin my-new-feature
  5. 提交 pull 请求 :D

许可

DateScrollPicker 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。

由 @alberdev 开发的库

AnimatedField  Logo ContentLoader  Logo CiaoTransitions  Logo DateScrollPicker  Logo EmptyStateKit  Logo GridTimerView  Logo PaintCodeKit  Logo