Tabbaritem's Badge

Source: Internet
Author: User

Many times we need to add some red badge on the Tabbaritem to prompt the user here to appear new content, can see, the most common is the circle of friends, the general Red Circle Badge contains 2 kinds of situations:

1) contains digital display

2) does not contain digital display

By default, the Tabbaritem already has the Badgevalue property, adding badge only need to set a Badgevalue value for item, in the case of 1) performance is very good, but in the case of 2) if the set Badgevalue is @ "" Then the Red badge will be very big and obviously inappropriate, so we need to make some adjustments as follows:

For (UIView *viewtab in tabbar.subviews) {for     (UIView *subview in viewtab.subviews) {           NSString *strclassname = [N Sstring Stringwithutf8string:object_getclassname (SubView)];           if ([strClassName isequaltostring:@ "Uitabbarbuttonbadge"] | |//* * * IOS 6 Prior is Uitabbarbuttonbadge               [ strClassName isequaltostring:@ "_uibadgeview"]) {        //* * * IOS posterior is Uitabbarbuttonbadge                                    cgrect Badgeframe = Subview.frame;                Badgeframe.size = Cgsizemake (8, 8);                Subview.frame = Badgeframe;                                    SubView.layer.masksToBounds = YES;                SubView.layer.cornerRadius = 4;                Subview.backgroundcolor = [Uicolor redcolor];                return;}}}      

first, you need to set the badge to set the item, and then add the above code, that is, the original Badgeview frame redefined a bit.

Tabbaritem of badge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.