iOS中类似微信红点显示功能
设计思路:给UIView增加一个分类所有的视图都可以根据需要来进行红点显示
#import<UIKit/UIKit.h> @interfaceUIView(CHRRedDot) @property(readonly,nonatomic)CALayer*chr_redDotLayer; /** 红点圆心的位置,与各个边之间的距离。如果距离<=0,则忽略距离 */ @property(nonatomic,assign)UIEdgeInsetschr_redDotEdgeInsets; /** 红点的半径,默认为4 */ @property(nonatomic,assign)CGFloatchr_redDotRadius; /** 红点的颜色,默认为0xFF5A5A */ @property(nonatomic,strong)UIColor*chr_redDotColor; /** 红点是否显示 */ @property(nonatomic,assign)BOOLchr_redDotShow; @end #pragmamark-method -(void)chr_updateRedDot{ CALayer*redDot=self.chr_redDotLayer; if(self.chr_redDotShow){ if(redDot==nil){ redDot=[CALayerlayer]; self.chr_redDotLayer=redDot; [self.layeraddSublayer:redDot]; } redDot.backgroundColor=self.chr_redDotColor.CGColor; [selfchr_layoutRedDot]; }else{ [redDotremoveFromSuperlayer]; self.chr_redDotLayer=nil; } } -(void)chr_layoutRedDot{ CALayer*redDot=self.chr_redDotLayer; if(redDot==nil)return; CGFloatradius=self.chr_redDotRadius; redDot.cornerRadius=radius; UIEdgeInsetsedgeInsets=self.chr_redDotEdgeInsets; CGFloatoriginX=edgeInsets.right<=0?edgeInsets.left-radius:self.bounds.size.width-edgeInsets.right+radius; CGFloatoriginY=edgeInsets.bottom<=0?edgeInsets.top-radius:self.bounds.size.height-edgeInsets.bottom+radius; CGFloatlength=radius*2; redDot.frame=CGRectMake(originX,originY,length,length); }
以上所述是小编给大家介绍的iOS中类似微信红点显示功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!