Similar to the micro-red dot display function in IOS _ios

Source: Internet
Author: User
Tags uikit

Design idea: Add a category to the UIView all views can be displayed as needed for red dots

#import <UIKit/UIKit.h> @interface UIView (Chrreddot) @property (readonly, nonatomic) Calayer * chr_reddotlayer; /** the position of the center of the red Dot, and the distance from each edge.
If the distance is <=0, the distance/@property (nonatomic, assign) Uiedgeinsets chr_reddotedgeinsets is ignored;
/** Red dot radius, the default is 4 * * * * @property (nonatomic, assign) CGFloat Chr_reddotradius;
/** red dot color, default to 0XFF5A5A * * * * @property (nonatomic, Strong) Uicolor * CHR_REDDOTCOLOR;
/** red dot whether show * * * @property (nonatomic, assign) BOOL chr_reddotshow;
  @end #pragma mark-method-(void) Chr_updatereddot {calayer *reddot = Self.chr_reddotlayer;
      if (self.chr_reddotshow) {if (RedDot = = nil) {RedDot = [calayer layer];
      Self.chr_reddotlayer = RedDot;
    [Self.layer Addsublayer:reddot];
    } Reddot.backgroundcolor = Self.chr_redDotColor.CGColor;
  [Self Chr_layoutreddot];
    else {[RedDot removefromsuperlayer];
  Self.chr_reddotlayer = nil;
  }-(void) Chr_layoutreddot {calayer *reddot = Self.chr_reddotlayer;
  if (RedDot = = nil) return; CGFloatradius = Self.chr_reddotradius;
  Reddot.cornerradius = radius;
  Uiedgeinsets edgeinsets = self.chr_reddotedgeinsets; CGFloat Originx = edgeinsets.right <= 0?
  Edgeinsets.left-radius:self.bounds.size.width-edgeinsets.right + radius; CGFloat originy = Edgeinsets.bottom <= 0?
  Edgeinsets.top-radius:self.bounds.size.height-edgeinsets.bottom + radius;
  CGFloat length = radius * 2;
Reddot.frame = CGRectMake (Originx, originy, length, length); }

The above is a small series of iOS to introduce similar micro-letter red dot display function, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

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.