Git Product home page Git Product logo

uibarbuttonitem-badge's People

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

uibarbuttonitem-badge's Issues

iOS 9 makes the badge a square?

UIBarButtonItem-Badge was working fine in iOS 8 but after upgrading to iOS 9 and Swift 2.0 the badge now shows up as a square. Anyone know a fix?

if badgeValue is "0",badgeLabel still exist ! UIButton+badge

hi, the judgement of badgeValue in setBadgeVaule method is wrong!.

I sepearate it in two judgements:
// When changing the badge value check if we need to remove the badge
if (!badgeValue || [badgeValue isEqualToString:@""]) {

    [self removeBadge];
}else if ([badgeValue isEqualToString:@"0"]){// && self.shouldHideBadgeAtZero error。

    [self removeBadge];
}

or if (badgeValue || [badgeValue isEqualToString:@""] || [badgeValue isEqualToString:@"0"] &&self.shouldHideBadgeAtZero )

shouldHideBadgeAtZero only works when set in the beginning

The config shouldHideBadgeAtZero only works when set before the badge count.

self.settingsBtn.badgeValue = "0"
self.settingsBtn.shouldHideBadgeAtZero = true

will display a badge with value 0.

When changing shouldHideBadgeAtZero it should take the current value into account and update.

The value cannot be updated immediately

swift code:
self.navigationItem.rightBarButtonItem?.badgeValue = "\(count)"

First time it can be updaed immediately. When the value changed the view only be updated after a few seconds.

It updated after about 7 seconds in rootviewconroller. But it even doen't work in pushed viewcontroller when the value changed.

Works with Swift?

I couldn't get this to work with Swift. The extensions on the buttons aren't recognized, such as badgeValue isn't found on the button. I think because there are special characters in the namespace so I can't import it (import UIBarButtonItem-Badge). Anyone got this to work with Swift that you can post a sample? I install it with CocoaPods.

PodSpec

Is your PodSpec working properly: I couldn't retrieve your project through cocoa-pod?

My podfile look like this:

source 'https://github.com/CocoaPods/Specs.git'

target "XEBTest" do
pod 'Reachability', '>3.2'
pod 'MIBadgeButton', '
>0.0.2'
pod 'UIBarButtonItem-Badge', '~>0.0.1'
end

target "XEBTestTests" do

end

Property shouldHideBadgeAtZero not working in 64bit environment

I have tried many different ways to send a "0" to the BadgeValue and no matter which way I send it, it displays a 0. I can only assume this is the case because this line of code:
[badgeValue isEqualToString:@"0"]
in the UIButton.m file does not seem to be running correctly. Even though I can not see any reason why it won't run correctly.

Here are the different ways I have tried to send a NSString amount to the Badge:
[NSString stringWithFormat:@"%ld", (long)updateNumber]
[NSString stringWithFormat:@"%d" ,updateNumber] //This way gives errors in the 64 bit environment
[NSString stringWithFormat:@"%lu", updateNumber]
[NSString stringWithFormat:@"%i", updateNumber]//Also more errors
[NSString stringWithFormat:@"%lu", (long)updateNumber]

None of the above work for me so I have had to add in code into my app that changes the "0" to a "".
I could be doing something else wrong but I can't see it.

By the way, this is a great badge icon addition to the UIButton and UIBarButton classes. I wish apple would add this code in so everyone could use it. Thank you for creating this!

make badge configuration order in-depended

Right now the badge looks different depending on when it's configured.

The configuration is only valid when applied after the badge count is set. The order should not matter.

        self.settingsBtn.badgeValue = "\(count)"

        let x = self.settingsBtn.badgeOriginX
        let y = self.settingsBtn.badgeOriginY

        self.settingsBtn.badgeOriginX = x - 10
        self.settingsBtn.badgeOriginY = y + 3
        self.settingsBtn.badgeFont = UIFont.systemFontOfSize(10)
        self.settingsBtn.badgePadding = 4

is not the same as

        let x = self.settingsBtn.badgeOriginX
        let y = self.settingsBtn.badgeOriginY

        self.settingsBtn.badgeOriginX = x - 10
        self.settingsBtn.badgeOriginY = y + 3
        self.settingsBtn.badgeFont = UIFont.systemFontOfSize(10)
        self.settingsBtn.badgePadding = 4

        self.settingsBtn.badgeValue = "\(count)"

UIButton

Nice extension !
Would be great to be able to use this on UIButton

Unable to set badgeOriginX and badgeOriginY (swift)

Hello, and thank you for this creation!
I'm using UIBarButtonItem-Badge with Swift and I can't seem to set the origin of the badge. It has no effect on the badge.

let button = UIBarButtonItem(image: buttonImage, style: .Plain, target: self, action: "buttonAction:")
button.shouldHideBadgeAtZero = true
button.badgeOriginX = -20

If I change it in badgeInit it works, but want to avoid modifying the original code.

After NSLogg'ing updateBadgeFrame it looks like it updates twice, the second time with the default value:
2015-03-04 12:59:00.367 myApp[123] Update badge frame x: -20.000000
2015-03-04 12:59:00.367 myApp[123] Update badge frame x: 24.000000

Thanks!

Xcode 8 Issue

The badge is not showing on Xcode 8 working fine on Xcode 7

Badge not showing in UIBarButtonItem

Hi, i am using this control for showing badge on barbuttonitem. it works fine for the first controller or root controller in navigation controller stack. While pushing to another controller, I tried to show badge and I cannot see any effect there. Can you help me to resolve this issue. It's very urgent for me now.

Issue with laying out badge before UIBarButtonItem / UIButton has it's frame set (autolayout).

One nice improvement that could be made to this library, is improving the flow in which the badge view gets built / laid out.

For instance, trying to add a badge to a UIButton that is being built using Autolayout and not having a specific frame set, then the badge is placed on the top left corner of the button by default.

Another example is if you set the badge properties before assigning the UIBarButtonItem to the navigationItem.rightBarButtonItem or navigationItem.rightBarButtonItems properties, the superview is nil.

Would be nice to change the logic of the badge to wait until it's superview (UIBarButtonItem or UIButton) has been fully laid out.

Add border to the badge

Hi,

I'm using this library and find it very simple and useful.
I want to add a border to my badge (border color and border width).
i modified method refreshBadge in the class UIBarButtonItem+Badge.m as follow:

// Handle badge display when its properties have been changed (color, font, ...)
- (void)refreshBadge
{
    // Change new attributes
    self.badge.textColor        = self.badgeTextColor;
    self.badge.backgroundColor  = self.badgeBGColor;
    self.badge.font             = self.badgeFont;
    self.badge.layer.borderColor= [UIColor whiteColor].CGColor;
    self.badge.layer.borderWidth= 1.5f;
    ....
}

So, I added these two lines:

    self.badge.layer.borderColor= [UIColor whiteColor].CGColor;
    self.badge.layer.borderWidth= 1.5f;

Please, could you add this in the library and make customizable.

Regards.

Badge does not appear on navigation item when reappeared

I have a UINavigationItem which contains three UIBarButtonItem.

I have used UIBarButtonItem+Badge to show badge on the middle UIBarButtonItem. Which appears perfectly fine.

Scenario for the problem that occurs is listed below.

  1. Store rightBarButtonItems in an array in viewDidLoad method/
  2. Add UISearchBar on as navigation title view.
  3. Remove UISearchBar when the work is done.
  4. Show rightBarButtonItems from the array previously stored.
  5. Call function to display badge on the middle UIBarButtonItem
  6. At this point badge does not appear. If I do further navigation and come back to the view it still does not appear.

Help me here. Thanks in advance.

badgevalue disappears if I change viewcontroller using pushViewController

For some strange reason if I change from screen A to screen B using a slidemenu with the pushViewController instruction the badgeValue disappears, but if I turn off animations it stays there.

This is the method I'm using.

func openViewControllerBasedOnIdentifier(_ strIdentifier:String){
let destViewController : UIViewController = self.storyboard!.instantiateViewController(withIdentifier: strIdentifier)

let topViewController : UIViewController = self.navigationController!.topViewController!

if (topViewController.restorationIdentifier! == destViewController.restorationIdentifier!){
    print("Same VC")
} else {
    var numeroProductos = String(Carrito.numProd)

    self.navigationController!.pushViewController(destViewController, animated: true)


  }
}

If instead of using .pushViewController I perform a normal segue this doesn't happen, in either case I load the badgeValue again on viewDidLoad. Any ideas? I'm using swift 3.0

Badge disappears when rotating to landscape on iPhone

This happens when the device is rotated to landscape, and the UIBarButtonItem has a landscapeImagePhone property (for showing a different image in landscape on iPhone).

Once this happens, the badge disappears for good, rotating back to portrait and trying to show the badge doesn't work.

Doesn't work when using more than one UIBarButtonItem on UINavigationItem

Hi,

I explain quickly my issue : i have two UIBarButtonItem added on a UINavigationItem :

self.navigationItem.rightBarButtonItems =
[NSArray arrayWithObjects:navRightButton, right2AddBarButtonItem, nil];

This allows me to have more than one button on the right hand side of the screen.

If i add a button made with your component, the badge doesn't appear.

If i do it the right way (only one button added via :
self.navigationItem.rightBarButtonItem = navRightButton;

it works like a charm...

Hope this a small adaptation...coz i find you'r component very convenient and well made...and i would really enjoy to use it

Thanks

Badge disappears when changing tintColor of item

Badge disappears when changing tintColor of item
Thats because internal view to which badge labels belongs recreated when tintColor changed.

i made workaround by checking superview of badge label:

-(UILabel_) badge {
UILabel_ lbl = objc_getAssociatedObject(self, &UIBarButtonItem_badgeKey);
if(lbl==nil || lbl.superview==nil || lbl.superview.superview==nil) {
lbl = [[UILabel alloc] initWithFrame:CGRectMake(self.badgeOriginX, self.badgeOriginY, 20, 20)];
[self setBadge:lbl];
[self badgeInit:lbl];
[self.customView addSubview:lbl];
lbl.textAlignment = NSTextAlignmentCenter;
}
return lbl;
}

also have to change badgeInit a little:

  • (void)badgeInit:(UIView*) badge
    {
    UIView *superview = nil;
    CGFloat defaultOriginX = 0;
    if (self.customView) {
    superview = self.customView;
    defaultOriginX = superview.frame.size.width - self.badge.frame.size.width/2;
    // Avoids badge to be clipped when animating its scale
    superview.clipsToBounds = NO;
    } else if ([self respondsToSelector:@selector(view)] && [(id)self view]) {
    superview = [(id)self view];
    defaultOriginX = superview.frame.size.width - badge.frame.size.width;
    }
    [superview addSubview:badge];

    // Default design initialization
    self.badgeBGColor = [UIColor redColor];
    self.badgeTextColor = [UIColor whiteColor];
    self.badgeFont = [UIFont systemFontOfSize:12.0];
    self.badgePadding = 6;
    self.badgeMinSize = 8;
    self.badgeOriginX = defaultOriginX;
    self.badgeOriginY = -4;
    self.shouldHideBadgeAtZero = YES;
    self.shouldAnimateBadge = YES;
    }

License

Hi, great work on this class. Can you please add a license for using it?
Please consider the MIT license as it's usually the easiest to work with for other developers.

Tapping on buttons with the badges sometime do not work

I implemented this library in my Swift project, and it works great. I really appreciate it.

The only problem I have is that tapping on the buttons with the badges sometime fails. I assume that it might be because badges do not accept touch gestures and the size of touchable area on the buttons becomes smaller.

Is possible to fix it?
Or is there any workaround?

Badge doesn't appear when using multiple items (i.e. rightBarButtonItems)

When adding multiple UIBarButtonItems to the navigation bar using the rightBarButtonItems property, the badge does not appear. This is a result of the bar button item which should display the badge having the customView property being nil.

Is it possible to apply a fix for this? Would love to use this library to show simple badges, but my app always has multiple UIBarButtonItems in the navigation bar.

Status bar overlaps Badge

When the Button with badge is displayed on navigation bar for the initial loading time, it gets displayed correctly. But when navigate back to the screen from its child screens, it gets overlapped by the status bar !

screenshot 2019-01-08 at 14 59 48

I checked the frame of the BarButtonItem on both scenarios, but found it is the same !

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.