zoukankan      html  css  js  c++  java
  • BlueBadge

    #import <UIKit/UIKit.h>

    @interface BlueBadge : UIView {

    NSInteger count;

    }

    @property (nonatomic) NSInteger count;

    - (void)drawWithCount:(NSInteger)i;

    @end

    #import "BlueBadge.h"

    @implementation BlueBadge

    @synthesize count;

    - (id)initWithFrame:(CGRect)frame {

        if (self = [super initWithFrame:frame]) {

            // Initialization code

    [self setBackgroundColor: [UIColor clearColor]];

    [self setCount: 0];

        }

        return self;

    }

    - (void)drawRect:(CGRect)rect {

    if (count == 0) return;

    NSString *countString = [NSString stringWithFormat: @"%d", count];

    UIFont *font = [UIFont boldSystemFontOfSize: 16];

    CGSize numberSize = [countString sizeWithFont: font];

    CGContextRef context = UIGraphicsGetCurrentContext();

    float radius = numberSize.height / 2.0;

    float startPoint = (rect.size.width - (numberSize.width + numberSize.height))/2.0;

    CGContextSetRGBFillColor(context, 0.55, 0.6, 0.70, 1.0);

    CGContextBeginPath(context);

    CGContextAddArc(context, startPoint + radius, radius, radius, M_PI / 2 , 3 * M_PI / 2, NO);

    CGContextAddArc(context, startPoint + radius + numberSize.width, radius, radius, 3 * M_PI / 2, M_PI / 2, NO);

    CGContextClosePath(context);

    CGContextFillPath(context);

    [[UIColor whiteColor] set];

    [countString drawInRect: CGRectMake(startPoint + radius, rect.origin.y, rect.size.width, rect.size.height) withFont: font];

    }

    - (void)drawWithCount:(NSInteger)i {

    self.count = i;

    [self setNeedsDisplay];

    }

    - (void)dealloc {

        [super dealloc];

    }

    @end

  • 相关阅读:
    操作标签的属性和属性值 table表格
    dom基本获取 标签文本操作
    延时器 清除延时器
    倒计时
    电子时钟
    时间戳
    设定时间的方法
    内置对象Date
    对象的基本特点
    终于有人把云计算、大数据和 AI 讲明白了【深度好文】
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/2458496.html
Copyright © 2011-2022 走看看