IGStoryButtonKit 1.0.1

IGStoryButtonKit 1.0.1

Kaoru Muta 维护。



  • 作者
  • Kaoru Muta

Swift-version CocoaPods License

简介

您是否看到过类似 Instagram 故事的用户界面?实际上,最近许多应用程序中已经实现了类似 Instagram 故事的功能。

为了快速实现这些功能,IGStoryButtonKit 提供了一个易于使用的按钮,称为 IGStoryButton,它具有丰富的动画和灵感来源于 Instagram 故事的多种方式。

使用和示例

显示类型

IGStoryButton 有四种显示类型;seenunseenstatusnone 作为 IGStoryButton.DisplayType 的一部分。(status 有两种类型;一种是将颜色作为参数设置,另一种是将图像作为参数设置。) IGStoryButton 的外观取决于这些显示类型。

颜色类型

围绕 IGStoryButton 的圆形环有四种颜色类型:defaultblackclearcustom 作为 IGStoryButton.ColorType 的一部分。

default black 清除 自定义颜色(colors
实际值 [UIColor.systemPink, UIColor.orange] [UIColor.black, UIColor.lightGray] [UIColor.clear] 参数中设置的值

根据特定显示和颜色类型的外观

详细情况如下。一旦只设置了DisplayType,外部圆环的颜色将自动设置为默认颜色。

已查看 未查看 状态(颜色:) 状态(图像:)
外观
默认颜色 ColorType.black ColorType.default ColorType.clear ColorType.clear ColorType.clear

自定义颜色和图像

您可以如下自定义设置圆环的颜色,以及状态视图(在下面的statusView中命名)的颜色和图像,以及将哪个图像设置为状态。如果您配置了IGStoryButton的显示和颜色类型,首先需要导入IGStoryButtonKit并将来自IGStoryButton.TypeCondition(它由IGStoryButton.DisplayTypeIGStoryButton.ColorType组成)的值设置到名为condition的属性中。

请参阅这些代码、注释以及名为ExampleApp的示例应用的实现。

// import this module
import IGStoryButtonKit

// storyButton: instance after initialization via code or interface builder
// set displayType as .seen, and default color is set to color of circle ring because colorType is not set specifically 
storyButton.condition = .init(display: .seen)
// same thing with above
storyButton.condition = IGStoryButton.TypeCondition(display: .seen)

// if you set color to statusView, you set StatusView.DisplayType.color(of:) as type and specific color as UIColor in the argument of StatusView.DisplayType.color
storyButton.condition = .init(display: .status(type: .color(of: UIColor.green)))

// if you set image to statusView, you set StatusView.DisplayType.image(of:) as TypeCondition.DisplayType and specific image as UIImage in the argument of StatusView.DisplayType.image
storyButton.condition = .init(display: .status(type: .image(of: UIImage(named: "ramen"))))

// if you customize color of circle ring, you set ColorType.custom(colors:) in the argument as TypeCondition.ColorType and set the specific array consisted of UIColor to the argument of ColorType.custom
storyButton.condition = .init(display: .status(type: .color(of: UIColor.green)), color: .custom(colors: [UIColor.cyan, UIColor.yellow, UIColor.gray]))

指示器操作

您可以操作圆环是否像活动指示器一样运行。如果您要开始加载,请执行startAnimating(speed:, alpha:)。同样地,如果要停止加载,请执行stopAnimating

// storyButton: instance after initialization via code or interface builder
// if you want to set rotation speed and alpha of button, set these in argument of startAnimating(speed:, alpha):
storyButton.startAnimating() // speed: 0.2, alpha: 0.7
storyButton.stopAnimating()

重要通知

IGStoryButton可以通过代码或界面构建器初始化,但宽度和高度的尺寸必须相等。如果宽度与其中一个尺寸不同,则预期会发生fatalError("The size of width and height are required to be equal")

需求

Swift 5.3+
iOS 13.0+
Xcode 12.0+

安装

CocoaPods

请将以下内容添加到您的 Podfile 中并执行 pod install

target 'MyApp' do
  pod 'IGStoryButtonKit'
end

Carthage

即将推出

Swift 包管理器

键入此内容作为 Swift 包:https://github.com/KaoruMuta/IGStoryButtonKit

贡献

如果发现任何问题,请在“问题”处通知我。此外,如果您提出并实现了新功能,请根据模板打开拉取请求。

让我们共同努力,使这款 OSS 对开发者更加方便!附带说明:我真的很高兴,并给我的 star 提供更多的动力!

未来工作

  • 引入带虚线的加载动画,使当前动画更丰富(高优先级,但似乎很难)
  • 样式设计有所不同(例如,边框的宽度)
  • 代码重构

许可

在MIT许可下