在Podfile中添加pod 'Sheriff'
,然后运行pod install
。
// Create your badge and add it as a subview to whatever view you want to badgify.
GIBadgeView *badge = [GIBadgeView new];
[myView addSubview:badge];
// Manually set your badge value to whatever number you want.
badge.badgeValue = 5;
// Or increment and decrement to your heart's content.
[badge increment];
[badge decrement];
自动处理显示和消失标签的动画。将标签值设置为一个正的非零整数将显示标签,反之,任何小于或等于零的值将消失标签。
很简单,不是吗?
当然可以...
badge.font = [UIFont fontWithName:@"OpenSans-Semibold" size:18];
badge.textColor = [UIColor whiteColor];
badge.backgroundColor = [UIColor colorWithRed:49/255.0 green:69/255.0 blue:122/255.0 alpha:1.0];
如果你想偏移标签,因为它没有放置得恰到好处:
badge.topOffset = 10; // Moves the badge down 10 points.
badge.rightOffset = 10; // Moves the badge right 10 points.
源代码在MIT许可证下提供。