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

  • 相关阅读:
    o9.17,习题
    09.17,二维数组,地图
    09.15,一维数组,冒泡排序
    09.11 小兔 成兔问题
    09.01,学习习题
    FTPHelper
    Wpf发送接收 win32消息
    win32Helper
    xml 封装类
    C# 多进程安全
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/2458496.html
Copyright © 2011-2022 走看看