测试测试 | ✗ |
语言语言 | SwiftSwift |
许可 | MIT |
发布最新发布 | 2017年12月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由 Dominik Butz 维护。
DYCornerBanner 是用 Swift 编写的,可以让您快速在矩形的任何视图上创建角标签,例如 UIImageView。角标签的旋转角度由 banners 视图的宽度和高度确定。
要运行示例项目,请克隆仓库,并首先从 Example 目录中运行 pod install
。
DYCornerBanner 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中:
pod 'DYCornerBanner'
确保将 DYCornerBanner 导入到您的 View Controller 子类中
import DYCornerBanner
查看以下示例。
@IBOutlet weak var cornerBannerBottomLeft: DYCornerBanner! // simply drop a UIView into the VC from interface builder in storyboard and set the UIView class to DYCornerBanner
override func viewDidLoad() {
super.viewDidLoad()
self.cornerBannerBottomLeft.setup(text: "Sunshine Guaranteed!", textColor: UIColor.black, bannerColor: UIColor.yellow, position: .bottomLeft)
}
另外,您可以按照以下方式在代码中创建一个角 banner 实例
let frame = CGRect(x: self.imageView.frame.size.width - 90, y: 0, width: 90, height: 90)
let bannerInCode = DYCornerBanner(frame: frame)
bannerInCode.setup(text: "Free Cocktails!", textColor: UIColor.red, bannerColor: UIColor.white.withAlphaComponent(0.6), position: .topRight)
self.imageView.addSubview(bannerInCode)
您可以按照以下方式覆盖 bannerWidth 和 textFont 的设置。
self.cornerBannerTopLeft.setup(text: "Just Added!", textColor: UIColor.white, bannerColor: UIColor.grassGreen(), position: .topLeft)
self.cornerBannerTopLeft.textFont = UIFont(name: "ChalkboardSE-Bold" , size: 15.0)!
self.cornerBannerTopLeft.bannerWidth = 17.0
转换为 Swift 4.0 之后(代码不需要转换)的小幅更改。
将标签的设置移动到 draw(rect:)
现在明确设置了横幅宽度(=标签高度),不再通过创建虚拟标签来获取其高度。现在可以覆盖调用setup前后文本字体和横幅宽度。
扩展文档
使用 cocoapods 模板重新创建项目。
发布于 2017-04-12。第一次发布!
dominikbutz, [email protected]
DYCornerBanner适用于MIT许可。请参阅LICENSE文件以获取更多信息。