CustomButton.m 1.51 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9
//
//  CustomButton.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/27.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "CustomButton.h"
曹云霄's avatar
曹云霄 committed
10
#import "instructionsLabe.h"
曹云霄's avatar
曹云霄 committed
11 12
#define WIDTH self.frame.size.width

曹云霄's avatar
曹云霄 committed
13

曹云霄's avatar
曹云霄 committed
14 15
@implementation CustomButton

曹云霄's avatar
曹云霄 committed
16

曹云霄's avatar
曹云霄 committed
17 18 19 20 21 22 23 24 25
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


曹云霄's avatar
曹云霄 committed
26

曹云霄's avatar
曹云霄 committed
27 28 29 30
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
曹云霄's avatar
曹云霄 committed
31
        self.titleLabel.font = [UIFont systemFontOfSize:11];
曹云霄's avatar
曹云霄 committed
32
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
勾芒's avatar
勾芒 committed
33
        self.adjustsImageWhenHighlighted = NO;
曹云霄's avatar
曹云霄 committed
34 35 36 37 38
    }
    return self;
}


曹云霄's avatar
曹云霄 committed
39 40 41 42 43 44 45 46 47 48 49
- (void)setInstructionsNumber:(NSInteger)instructionsNumber
{
    _instructionsNumber = instructionsNumber;
    for (UIView *subview in self.subviews) {
        
        if ([subview isKindOfClass:[instructionsLabe class]]) {
            
            [subview removeFromSuperview];
            break;
        }
    }
勾芒's avatar
勾芒 committed
50 51 52 53 54
    if (_instructionsNumber) {
        instructionsLabe *labe = [[instructionsLabe alloc]initWithFrame:CGRectMake(WIDTH-35, 0, 13, 13)];
        labe.instructionsNumber = _instructionsNumber;
        [self addSubview:labe];
    }
曹云霄's avatar
曹云霄 committed
55 56 57 58
}



曹云霄's avatar
曹云霄 committed
59 60
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
曹云霄's avatar
曹云霄 committed
61
    return CGRectMake((WIDTH-25)/2, 0, 25, 25);
曹云霄's avatar
曹云霄 committed
62 63 64 65
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
曹云霄's avatar
曹云霄 committed
66
    return CGRectMake(0, 30, WIDTH, 20);
曹云霄's avatar
曹云霄 committed
67 68 69 70 71 72 73 74
}







勾芒's avatar
勾芒 committed
75 76


曹云霄's avatar
曹云霄 committed
77
@end