NativePopup
NativePopup
是 Apple iOS AppStore 审查反馈弹窗的克隆。
NativePopup 复制了原生的弹窗设计和行为(动画和用户交互)。您可以使用自定义图像和表情符号,除了不良/好评图标。
与 Apple 原始弹窗相比。
NativePopup | 原始 |
---|---|
![]() |
![]() |
![]() |
![]() |
示例
好评/差评
好评 | 差评 |
---|---|
![]() |
![]() |
自定义图像/表情
自定义图像 | 表情 |
---|---|
![]() |
![]() |
使用说明
使用 NativePopup 非常简单
// Good
NativePopup.show(image: Preset.Feedback.good,
title: "Helpful",
message: "Thanks for your feedback.")
// Bad
NativePopup.show(image: Preset.Feedback.bad,
title: "Not Helpful",
message: "Thanks for your feedback.")
// Custom Image
NativePopup.show(image: UIImage(named: "love")!,
title: "参考になった",
message: "フィードバックをありがとう\nございました。")
// Emoji
NativePopup.show(image: Character("🐶"),
title: "イッヌ",
message: "絵文字対応したワン")
// Title only
NativePopup.show(image: Preset.Feedback.good,
title: "Empty Message 🗑",
message: nil)
// Custom duration (default duration is 1.5 seconds)
NativePopup.show(image: Character("🔟"),
title: "10 seconds",
message: "Long duration🙇",
duration: 10)
// Like Apple Music
NativePopup.show(image: Preset.Feedback.done,
title: "Added to Library",
message: nil,
initialEffectType: .fadeIn)
image
接受 ImageConvertible
协议。
public enum Image {
case image(UIImage)
case emoji(Character)
func validate() {
switch self {
case .image(let image):
assert(image.size.width == image.size.height, "Aspect ratio should be 1:1.")
case .emoji:
// MEMO: should check?
break
}
}
}
public protocol ImageConvertible {
var npImage: Image { get }
}
UIImage
和 Character
默认符合 ImageConvertible
。
extension UIImage: ImageConvertible {
public var npImage: Image { return .image(self) }
}
extension Character: ImageConvertible {
public var npImage: Image { return .emoji(self) }
}
可以如下定义自定义预置图片。
extension NativePopup {
public struct Preset {
private init() {}
public enum Feedback: String, ImageConvertible {
case
good,
bad
public var npImage: Image {
return .image(UIImage.init(nativePopupNamed: "feedback_\(rawValue)"))
}
}
}
}
图片大小应为 112 x 112。
安装
可通过 Carthage 安装,或手动添加 NativePopup 源码。
Carthage
将以下内容添加到 Cartfile
github "mono0926/NativePopup"
$ carthage update