Giter Club home page Giter Club logo

wzlbadge's Introduction

一行代码实现Badge效果(iOS) BADGE IN ONE LINE(iOS)

OVERVIEW

WZLBadge is a tool to add or clear badge for any UIViews, which is written in Objective-C, supporting iOS5 or above, supporting portrait and landscape device orientation.

The code is implemented by the way of category for UIView, thus, it is very easy to use.

At this version, three badge style are supported:

  • WBadgeStyleRedDot
  • WBadgeStyleNumber
  • WBadgeStyleNew

Three animation types are supported:

  • WBadgeAnimTypeNone(by default)
  • WBadgeAnimTypeScale
  • WBadgeAnimTypeShake
  • WBadgeAnimTypeBreathe
  • WBadgeAnimTypeBounce

Here are examples for WZLBadge(just show static picture without gif here):


INSTALLTATION

Method1: Drag the

WZLBadge

folder into your project.

Method2: Use CocoaPods to install automaticlly:

pod 'WZLBadge'


REQUIREMENTS

  • Xcode 6
  • iOS5 or above
  • ARC (or MRC, but project setting is necessary)

USAGE

  1. Add the following import to the top of the file:

import "WZLBadgeImport.h"

  1. Use the following to display badge easily:

[someView showBadgeWithStyle:WBadgeStyleRedDot value:0 animationType:WBadgeAnimTypeShake]; [someView showBadgeWithStyle:WBadgeStyleNumber value:99 animationType:WBadgeAnimTypeShake];

or simply call interface:[- showBadge]

  1. Use the following to hide badge easily:

[someView clearBadge];

4.Use the following to resume badge when it has been hidden:

[someView resumeBadge];


BADGE CUSTOMIZATION

Feel free to customize badge size, position, animation style or anything else.

WZLBadge provides easy way to customize its style.:

//set background color. red color by default
view.badgeBgColor = [UIColor purpleColor];

//set badge position. right-top corner of view by default
view.badgeCenterOffset = CGPointMake(-8, 0);

//set badge foreground color. white color by default
view.badgeTextColor = [UIColor whiteColor];

//...

CONTACT

Do you have any questions or idea? My email is:

[email protected]

Or you can find some more info at my blog in cnblogs.com:

http://www.cnblogs.com/wengzilin/

如果你在天朝,可以查看中文博客地址: http://www.cnblogs.com/wengzilin/p/4633937.html


NOTE

This project will be update continually. Therefore, fork or star would be suggested.

I wish it to be an ultimat solution for UIView badge in iOS.


AUTHOR

Zilin Weng(翁子林) https://github.com/weng1250


CONTRIBUTE

Feel free to open an issue or pull request, if you need help or there is a bug.


CHANGE LOG

v1.2.6 2017.4.20 Bugs were fixed. Enable setting badge properties before bage initialization.

v.1.2.5 2017.3.1 fix bug 'when showing TabbarItem bage, badge is covered by tabbarItem icon'

v1.2.3 2016.2.15 1.Enable resume badge when badge has been cleard(removed)

V1.2.2 2015.12.18 1.Enable badge font customization 2.code warning removed

V1.2 2015.09.25 1.UITabBarItem badge is supproted; 2.Enable change badge properties when badge is showing; 3.Other code optimization.

V1.1 2015.08.12

  1. UIBarButtonItem badge is supported. UIBarButtonItem is kind of NSObject and its displayed view is invisiable. This version makes usage of UIBarButtonItem badge as to UIView.
  2. Slight adjustment for code structure to fit future extension.
  3. Other code optimization.

V1.0 at 2015.06.16

Base functions are completed, which is able to meet most of requirements.



LICENSE

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

wzlbadge's People

Contributors

helinyu avatar jfuellert avatar katerynasytnyk avatar weng1250 avatar weng1252 avatar zhangao0086 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wzlbadge's Issues

iOS11兼容性问题

iOS11

  • (UIView *)getActualBadgeSuperView
    {
    return [self valueForKeyPath:@"_view"];
    }

[self valueForKeyPath:@"_view"]返回nil,无法获取UIBarButtonItem的view,小红点加不上

Autolayout不能自动更新

我的TableViewCell使用xib自动布局, 当xib中的cell高度和代码中不一致时,WZLBadge显示的位置会以xib中的为准,同样的Label使用自动布局时也无法根据文字长度更新badge位置。

iOS 11 适配问题

在iOS 11 中 使用push切换页面 过后badge 会莫名其妙跑 UIBarButtonItem 下层去.

在UIButton上不显示badge

在一般的UIView上都能正常显示,但是在UIButton上设置了以后没有用,badge显示不出来。

badge位置问题

当我用UITabBarItem+WZLBadge.h这个类别的时候,修改了badgeContentOffset属性,使得badge的UILabel和UITabBarItem上的图片距离更近一些。这时如果这两个view有重叠时,重叠部分的badge会被tabbarItem的图片遮住,请问这个问题如何解决

deprecated warning

WZLBadge/View/UIView+WZLBadge.m:153:27: 'sizeWithFont:constrainedToSize:lineBreakMode:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithSize:options:attributes:context:

在UIView+WZLBadge中

[obj integerValue];

Cannot initialize return object of type 'WBadgeAnimType' with an rvalue of type 'NSInteger' (aka 'long')

Badge is not always showing

I have a 3 UIView controller and they are called in sequence in navigation stack.
VC1->VC2->VC3

VC2 has UIBarButtonItem and it shows number of cart items in viewWillAppear() and it doesn't show when pushed from VC1, but shows when popping from VC3.

Here is code

@IBOutlet weak var cartItem: UIBarButtonItem!

override func viewWillAppear(_ animated: Bool) {
        if count == 0 {
            self.cartItem.clearBadge()
        } else {
            self.cartItem.badgeBgColor = UIColor(hex:"71c386")
            self.cartItem.badgeCenterOffset = CGPoint(x:-16, y:0)
            self.cartItem.badgeFont = UIFont.boldSystemFont(ofSize: 12)
            self.cartItem.showBadge(with: .number, value: count, animationType: .none)
        }
}

I am using Xcode 8.3.2 and testing on iOS 10.3.1 iPhone 6 plus.

Autolayout issue

A customised button with text and imageView placed on the table view cell, and using Masonry for auto layout.
I want to show badge number upon the imageView. Call show badge function likes in the cellForRow atIndexPath.
cell.btn.iconImageView showBadgeWithStyle:WBadgeStyleNumber...

Here the issue coming, the badge displays on the top left of the imageView. And I lookup the lib code, the badgeInit function try to get self.frame with zero. That's the bug I thoughts.
Am I clearly explained? Thx.

badge不显示!!

打印self.badge 为null, 其它属性也是null, 不知道是不是和什么冲突了, 前一个项目用就可以正常显示, 这个新项目就不行。查看视图层级, 没有badgeLabel这个控件, 什么情况会产生这种原因?

不能修改数值

- (void)showNumberBadgeWithValue:(NSInteger)value{
if (value < 0) {
    return;
}
[self badgeInit];
if (self.badge.tag != WBadgeStyleNumber) {
    self.badge.tag = WBadgeStyleNumber;

    //maximun value allowed is 99. When the value is greater than 99, "99+" will be shown.
    if (value >=100) {
        self.badge.text = @"99+";
    } else {
        self.badge.text = [NSString stringWithFormat:@"%@", @(value)];
    }
    [self adjustLabelWidth:self.badge];
    self.badge.width = self.badge.width - 4;
    self.badge.height = 12;
    if (self.badge.width < self.badge.height) {
        self.badge.width = self.badge.height;
    }

    self.badge.center = CGPointMake(self.width + 2 + self.badgeCenterOffset.x, self.badgeCenterOffset.y);
    self.badge.font = [UIFont boldSystemFontOfSize:9];
    self.badge.layer.cornerRadius = self.badge.height / 2;
}
self.badge.hidden = NO;
if (value == 0) {
    self.badge.hidden = YES;
}

}

问题应该在于这里。可以看出,再次调用,value不会重新赋值。因此造成数字有更新,但是调用无反应。

加入pod

不错的工程,赞一个,能加入cocoapod支持就完美了

小红点clear后,再次show无效

亲,感谢你的WZLBadge,用着很爽,很佩服你。
今天在运行的时候发现,如果UIBarButtonItem clearBadge之后,如果再show,就怎么也show不出来,请问有办法解决吗?3Q

Breaking other UIView customizations

I have other customised views and this Pod is breaking all of them...

I have a view to round up the profile picture for example and just by adding this pod the picture became squared again.

第一次进入页面红点没有显示

Xcode9.0.1
iOS 11

如上,使用该库,第一次进入页面,设置的导航栏的UIBarButtonItem 小数字红圈时,没有第一时间显示,第二次进入页面就又显示了。

有其他小伙伴遇到该问题吗,有结局的办法吗?

注意是导航栏上的UIBarButtonItem 设置数字角标。。。

UITableViewCell中添加位置不对

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomTableViewCell" forIndexPath:indexPath];
    [cell.avator showBadge];
    return cell;
    }

2018-10-26 3 33 01

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.