单军华
2016-12-21 8329ef237d1841d377718813a0b452ea0df64378
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
//  JHShowInfoView.m
//  JHChartDemo
//
//  Created by cjatech-简豪 on 16/5/4.
//  Copyright © 2016年 JH. All rights reserved.
//
 
#import "JHShowInfoView.h"
 
 
@interface JHShowInfoView ()
 
 
@property (nonatomic,strong) UILabel * bgLabel;
 
@end
 
 
@implementation JHShowInfoView
 
 
-(instancetype)init{
    
    if (self = [super init]) {
        self.layer.borderWidth  = 2;
        self.layer.cornerRadius = 5;
        self.clipsToBounds      = YES;
        self.layer.masksToBounds = YES;
        self.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
    }
    
    return self;
    
}
 
 
-(void)setShowContentString:(NSString *)showContentString{
    
    
    _showContentString = showContentString;
    CGSize size = [showContentString boundingRectWithSize:CGSizeMake(50, 100) options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:8],NSForegroundColorAttributeName:[UIColor darkGrayColor]} context:nil].size;
    
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, size.width+10, 30);
    
    if (_bgLabel==nil) {
        
        _bgLabel = [[UILabel alloc] initWithFrame:self.bounds];
        _bgLabel.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
        _bgLabel.backgroundColor = [UIColor clearColor];
        _bgLabel.font = [UIFont systemFontOfSize:8];
        _bgLabel.textColor = [UIColor blackColor];
        _bgLabel.numberOfLines = 2;
        [self addSubview:_bgLabel];
        
    }
    _bgLabel.frame = CGRectMake(0, 0, size.width, size.height);
    _bgLabel.text = _showContentString;
    _bgLabel.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
    
}
 
-(void)updateFrameTo:(CGRect)frame andBGColor:(UIColor *)bgColor andShowContentString:(NSString *)contentString{
    self.showContentString = contentString;
    
    [UIView animateWithDuration:0.5 animations:^{
 
        
        
        self.layer.borderColor = bgColor.CGColor;
 
        self.center = CGPointMake(frame.origin.x, frame.origin.y);
        
    } completion:^(BOOL finished) {
        
    }];
    
}
 
@end