Glyptodon 2.0.0

Glyptodon 2.0.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年4月
SwiftSwift版本3.0
SPM支持SPM

Evgenii Neumerzhitckii维护。




Glyptodon 2.0.0

  • Evgenii Neumerzhitckii

为iOS提供“无内容”消息叠加层

这是用Swift编写的iOS UI控件,它在现有视图上显示“无内容”消息。当您想要在现有视图上显示缺失内容消息并建议一个动作时,这可能很有用。例如:“购物车为空”、“没有新消息”、“没有收藏”、“没有评论”等。

例如,假设我们正在构建一个购物应用的购物车屏幕。当购物车为空时,我们可以显示“购物车为空”消息和“搜索”按钮。

Glyptodon iOS message view example

以下是使用Glyptodon在你的现有视图中显示“购物车为空”消息的方法

view.glyptodon.show("Cart is empty", withButton: "Search") {
  // User has tapped the "Search" button.
}

如何工作

  • view.glyptodon.show方法会将一个子视图添加到你的现有视图中。
  • 你可以通过调用view.glyptodon.hide()来移除glyptodon视图。
  • Glyptodon视图像一个叠加层一样填充你的视图的整个区域。
  • 你可以通过对要显示它的视图进行指定来完全控制Glyptodon叠加层的放置。这个视图可以是你的视图控制器的根视图,也可以是任何其他的UIView对象。

设置

有三种方法可以将Glyptodon添加到你的项目中。

添加源代码(iOS 7+)

只需将GlyptodonDistrib.swift文件添加到Xcode项目中。

使用Carthage设置(iOS 8+)

github "marketplacer/Glyptodon" ~> 2.0添加到你的Cartfile中,然后运行carthage update

使用CocoaPods设置(iOS 8+)

如果你在使用CocoaPods,请将此文本添加到你的Podfile中,然后运行pod install

use_frameworks!
target 'Your target name'
pod 'Glyptodon', '~> 2.0'

用法

如果你使用了Carthage或CocoaPods设置方法,请将import Glyptodon添加到你的源代码中。

Glyptodon是UIView类的一个扩展。你可以通过任何UIView或其子类的实例使用glyptodon属性来访问它。例如,这是你的视图控制器的view属性。

显示和隐藏消息视图

// Show message
view.glyptodon.show("No new messages")

// Hide message
view.glyptodon.hide()

// Show message with a button
view.glyptodon.show("Cart is empty", withButton: "Go shopping") {
  // Do something when the button is tapped.
}

样式化

在显示视图之前,将glyptodon.style属性设置以样式化视图。有关完整的配置选项列表,请参阅样式手册

// Set the view background color
view.glyptodon.style.view.backgroundColor = GlyptodonColor.fromHexString("#EEEEEE")

// Set the title font
view.glyptodon.style.title.font = UIFont.preferredFontForTextStyle(UIFontTextStyleTitle1)

// Set the title color
view.glyptodon.style.title.color = GlyptodonColor.fromHexString("#666666")

// Set the button font
view.glyptodon.style.button.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)

// Set the button color
view.glyptodon.style.button.color = GlyptodonColor.fromHexString("#007AFF")

// Set the color of the tapped button
view.glyptodon.style.button.colorHighlighted = GlyptodonColor.fromHexString("#007AFF33")

单元测试

有时在单元测试中验证消息视图及其内容的存在是有用的。该库提供了以下辅助属性,以简化单元测试。

// Indicates if the view is currently visible
view.glyptodon.visible

// Returns the currently displayed title label
view.glyptodon.titleLabel

// Returns the currently displayed button
view.glyptodon.button

示例

该项目包含一个演示iOS应用。

Glyptodon demo iOS app

许可证

Glyptodon库是在MIT许可证下发布的。

Glyptodon library for iOS