1. Use the system comes with, and can display the number on the Little red dot.
[ItemOne Setbadgevalue:@ ""// show Little Red dots without numbers [itemone setbadgevalue:@ "1 "]; // show Little Red dots with numbers
The above shortcomings: Little red dot too big, hurt Ah!
2. Use the picture, create the picture, set the rendering of the picture.
UIImage * Normalimage = [[UIImage imagenamed:@"Pic_msg_yes_nor"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; UIImage* Selectimage = [[UIImage imagenamed:@"Pic_msg_yes_sel"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Uitabbaritem*itemone=[[uitabbaritem Alloc]initwithtitle:@"message"image:normalimage Selectedimage:selectimage];/** Set the rendering mode of UIImage: Uiimage.renderingmode Coloring (Tint Color) is one of the iOS7 interfaces. Set the rendering mode of the UIImage: Uiimage.renderingmode A significant change, you can set a UIImage whether to use the tint Color of the current view when rendering. UIImage added a read-only property: Renderingmode, corresponding to a new method: Imagewithrenderingmode:, It uses the Uiimagerenderingmode enumeration value to set the Renderingmode property of the picture. The enumeration contains the following values: Uiimagerenderingmodeautomatic//automatically adjusts the rendering mode based on the environment in which the picture is used and the drawing context in which it is located. Uiimagerenderingmodealwaysoriginal//Always draws the original state of the picture without using tint Color. Uiimagerenderingmodealwaystemplate//Always draws a picture based on tint color, ignoring the color information of the picture. The default value for the Renderingmode property is Uiimagerenderingmodeautomatic*/
Disadvantage: This will only show the small red dots, can not display the specific number. But the landlord of the project does not need to display the numbers, the use of this. Convenient and concise.
3. Using Catgory, expand Uitabbar
This method is reproduced from: http://blog.csdn.net/lilinoscar/article/details/47103747
The first step is to build a uitabbar category.
The second step is to write the code.
. h file
[OBJC]View Plaincopy
- #import <UIKit/UIKit.h>
- @interface Uitabbar (Badge)
- -(void) Showbadgeonitemindex: (int) index; //show Little red dot
- -(void) Hidebadgeonitemindex: (int) index; //Hide Little Red dot
- @end
. m file
[OBJC]View Plaincopy < param name= "wmode" value= "Transparent" >
- #import "Uitabbar+badge.h"
- #define The number of Tabbaritemnums 4.0//tabbar if 5 is set to 5.0
- @implementation Uitabbar (Badge)
[OBJC]View Plaincopy
- Show Little Red Dot
- -(void) Showbadgeonitemindex: (int) index{
- //Remove the Little red dot before
- [self removebadgeonitemindex:index];
- //New Little Red dot
- UIView *badgeview = [[UIView alloc]init];
- Badgeview. Tag = 888 + index;
- Badgeview. Layer. Cornerradius = 5; Round
- Badgeview. backgroundcolor = [Uicolor redcolor]; Color: Red
- CGRect tabframe = self. frame;
- //Determine the location of the Little red dot
- float Percentx = (index +0. 6)/tabbaritemnums;
- CGFloat x = CEILF (percentx * tabframe. Size. width);
- CGFloat y = Ceilf (0. 1 * tabframe. Size. height);
- Badgeview. frame = CGRectMake (x, y, 10, 10); Round size is ten
- [self addsubview:badgeview];
- }
[OBJC]View Plaincopy < param name= "wmode" value= "Transparent" >
- Hide the Little Red dot
- -(void) Hidebadgeonitemindex: (int) index{
- //Remove the Little red dot
- [self removebadgeonitemindex:index];
- }
[OBJC]View Plaincopy
- Remove the Little red dot
- -(void) Removebadgeonitemindex: (int) index{
- //Remove according to tag value
- For (UIView *subview in self. subviews) {
- if (subView. Tag = = 888+index) {
- [SubView Removefromsuperview];
- }
- }
- }
- @end
The third step is to introduce the classes that need to be used.
[OBJC]View Plaincopy
- #import "Uitabbar+badge.h"
The reference code is as follows:
[OBJC]View Plaincopy < param name= "wmode" value= "Transparent" >
- Show
- [self. Tabbarcontroller. TabBar Showbadgeonitemindex:2];
- Hide
- [self. Tabbarcontroller. TabBar Hidebadgeonitemindex:2]
A project needs to show a little red dot on the Uitabbar, where three methods are collected.