//
//  SuspensionView.m
//  Huangshan
//
//  Created by xiejiangbo on 2018/10/16.
//  Copyright © 2018 yin chen. All rights reserved.
//

#import "SuspensionView.h"
@interface SuspensionView ()
@property(nonatomic,strong)UILabel *suspensionLab;
@property(nonatomic,strong)UIButton *suspensionBtn;

@end

@implementation SuspensionView
+ (SuspensionView *)ShareSuspensionView{
    static SuspensionView *suspensionView = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        suspensionView = [[SuspensionView alloc]init];
    });
    return suspensionView;
}
- (UILabel *)suspensionLab
{
    if (!_suspensionLab) {
        _suspensionLab = [[UILabel alloc]init];
        _suspensionLab.textAlignment = NSTextAlignmentLeft;
        _suspensionLab.font = [UIFont systemFontOfSize:16];
        _suspensionLab.numberOfLines = 0;
        _suspensionLab.layer.masksToBounds = true;
        _suspensionLab.layer.cornerRadius = 3;
//        _suspensionLab.textColor = COLOR_WITH_HEX(0x333333);
        _suspensionLab.textColor = [UIColor whiteColor];
        _suspensionLab.backgroundColor = COLOR_WITH_HEX(0x999999);
        _suspensionLab.hidden = YES;
    }
    return _suspensionLab;
}
-(void)setBenCent:(CGPoint )center{
    self.suspensionBtn.center = center;
    self.suspensionLab.frame = CGRectMake(_suspensionBtn.centerX+_suspensionBtn.width/2+15, _suspensionBtn.centerY-_suspensionLab.height/2, _suspensionLab.width, _suspensionLab.height);
}
- (UIButton *)suspensionBtn{
    if (!_suspensionBtn) {
        _suspensionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_suspensionBtn setBackgroundImage:[UIImage imageNamed:@"aiui_image"] forState:UIControlStateNormal];
    }
    return _suspensionBtn;
}
-(UIButton *)getsuspensionBtn{
    return self.suspensionBtn;
}
-(UILabel *)getsuspensionLabel{
    return self.suspensionLab;
}
-(void)setSuspensionLabel:(NSString *)text{
    self.suspensionLab.frame = CGRectMake(_suspensionLab.originX, _suspensionLab.originY, [self widthForString:text fontSize:16 andHeight:_suspensionLab.height], _suspensionLab.height);
    self.suspensionLab.alpha = 1;
    self.suspensionLab.hidden = NO;
    self.suspensionLab.text = text;
    [UIView animateWithDuration:3 animations:^{
        self.suspensionLab.alpha = 0.8;
    } completion:^(BOOL finished) {
        self.suspensionLab.hidden = YES;
    }];
   
}
-(float) widthForString:(NSString *)value fontSize:(float)fontSize andHeight:(float)height
{
    CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(CGFLOAT_MAX, height) lineBreakMode:NSLineBreakByWordWrapping];
   return sizeToFit.width;
}

@end
