Ios is similar to WeChat red dot display, and ios is similar to display

Source: Internet
Author: User

Ios is similar to the red dot display function, and ios is similar to the display function.

Design Concept: Add a category to UIView. All views can be highlighted in red as needed.

# Import <UIKit/UIKit. h> @ interface UIView (CHRRedDot) @ property (readonly, nonatomic) CALayer * chr_redDotLayer;/** the distance between the center of the red dot and each edge. If the distance is <= 0, the distance */@ property (nonatomic, assign) UIEdgeInsets chr_redDotEdgeInsets;/** indicates the radius of the red dot. The default value is 4 */@ property (nonatomic, assign) CGFloat chr_redDotRadius;/** the color of the red dot. The default value is 0xFF5A5A */@ property (nonatomic, strong) UIColor * chr_redDotColor;/** whether the red dot displays */@ property (nonatomic, assign) BOOL chr_redDotShow; @ end # pragma mark-method-(void) chr_updateRedDot {CALayer * redDot = self. chr_redDotLayer; if (self. chr_r EdDotShow) {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; CGFloat radius = self. chr_redD OtRadius; redDot. cornerRadius = radius; UIEdgeInsets edgeInsets = self. chr_redDotEdgeInsets; CGFloat originX sets = 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 );}

 

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.