Display badge (compatible with ios6) on any uiview)

Source: Internet
Author: User

I have previously written an article to show badge on any uiview, but the ios6 fails. It turns out that Apple has changed the badge class name, so it is compatible here. The source code is as follows:

-(Uiview *) showbadgevalue :( nsstring *) strbadgevalue {uitabbar * tabbar = [[uitabbar alloc] initwithframe: cgrectmake (0, 0,320, 50)]; uitabbaritem * Item = [[uitabbaritem alloc] initwithtitle: @ "Image: Nil Tag: 0]; item. badgevalue = strbadgevalue; nsarray * array = [[nsarray alloc] initwithobjects: item, nil]; tabbar. items = array; [item release]; [array release]; // search for (uiview * viewtab in tabbar. subviews) {for (uiview * subview in viewtab. subviews) {nsstring * strclassname = [nsstring stringwithuf8string: object_getclassname (subview)]; If ([strclassname isw.tostring: @ "uitabbarbuttonbadge"] | [strclassname isw.tostring: @ "_ uibadgeview"]) {// remove [subview removefromsuperview] from the original view; // [self addsubview: subview]; subview. frame = cgrectmake (self. frame. size. width-subview.frame.size.width, 0, subview. frame. size. width, subview. frame. size. height); [tabbar release]; return subview ;}} [tabbar release]; return nil ;}- (void) removebadgevalue {// For (uiview * subview in self. subviews) {nsstring * strclassname = [nsstring stringwithuf8string: object_getclassname (subview)]; If ([strclassname isw.tostring: @ "uitabbarbuttonbadge"] | [strclassname isw.tostring: @ "_ uibadgeview"]) {[subview removefromsuperview]; break ;}}}

One method is used to show badge, and the other is used to hide (remove.

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.