SYSquareButton
SYSquareButton 可以自定义您想要的徽章按钮。
特性
- 可以在 Storyboard 中实现。
- 易于使用,高度可定制。
- 支持所有位置。
屏幕截图
要求
- iOS 8.0+
- Swift 4
安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
要使用 CocoaPods 将 SYBadgeButton 集成到您的 Xcode 项目中,请在其 Podfile 中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target '<Your Target Name>' do
pod 'SYBadgeButton'
end
然后,请运行以下命令
$ pod install
使用方法
无代码 Storyboard 实现
首先,将自定义类 SYBadgeButton
添加到您的按钮中
您可以在属性检查器中看到自定义属性
代码实现
首先
import SYBadgeButton
然后,初始化您的按钮
let rect = CGRect(x: 20, y: 20, width: 100, height: 50)
let badgeButton = SYBadgeButton(frame: rect)
badgeButton.setTitle("button", for: .normal)
badgeButton.setTitleColor(UIColor.black, for: .normal)
view.addSubview(badgeButton)
添加徽章值
badgeButton.badgeValue = "20"
自定义徽章颜色
badgeButton.badgeBackgroundColor = UIColor.brown
badgeButton.badgeTextColor = UIColor.white
有多个位置选项
// This is topLeft position, and default is topRight position by 0
badgeButton.badgePositionIndex = 1
您还可以使用徽章偏移和边缘内缩
// Custom offset and edge inset
badgeButton.badgeOffset = CGPoint(x: 3, y: 3)
badgeButton.leftEdgeInset = 10
badgeButton.rightEdgeInset = 10
badgeButton.topEdgeInset = 5
badgeButton.bottomEdgeInset = 5
授权
SYBadgeButton 在 MIT 许可证下可用。有关更多信息,请参阅 MIT 许可证。