//
//  TLMenuButton.m
//  MiShu
//
//  Created by tianlei on 16/6/21.
//  Copyright © 2016年 Qzy. All rights reserved.
//

#import "TLMenuButton.h"


@implementation TLMenuButton
//- (CGRect)imageRectForContentRect:(CGRect)contentRect
//{
//    return CGRectMake(15, 8, 50, 45);
//}
//
//- (CGRect)titleRectForContentRect:(CGRect)contentRect
//{
//    return CGRectMake(0,62, self.bounds.size.width, 18);
//}

- (void)setTitle:(NSString *)title forState:(UIControlState)state{
    [super setTitle:title forState:state];
    self.titleLabel.font = [UIFont systemFontOfSize:12];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}


- (void)setImage:(UIImage *)image forState:(UIControlState)state{
    [super setImage:image forState:state];
}
+ (instancetype)buttonWithTitle:(NSString *)title imageTitle:(NSString *)imageTitle center:(CGPoint)point model:(KKRedPackageClickEventModel *)model{
    //CGSize size = CGSizeMake(44, 44);
    CGRect frame = CGRectMake(0, 0, 80, 80);
    TLMenuButton *menu4 = [[TLMenuButton alloc] initWithFrame:frame];
    menu4.center = point;
    //menu4.backgroundColor = color;
    //menu4.layer.cornerRadius = 55/2.0;
    if (model) {
        [menu4 setTitle:model.menuName forState:UIControlStateNormal];
        [menu4 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KKFindPackageIP,model.menuIcon]]  forState:UIControlStateNormal completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            UIImage *refined = [UIImage imageWithCGImage:image.CGImage scale:2.0 orientation:image.imageOrientation];
            [menu4 setImage:refined forState:UIControlStateNormal];
            [menu4 layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleTop imageTitleSpace:4];
        }];
    }else{
        [menu4 setTitle:title forState:UIControlStateNormal];
        [menu4 setImage:[UIImage imageNamed:imageTitle] forState:UIControlStateNormal];
    }
   
    [menu4 layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleTop imageTitleSpace:4];
    return menu4;
}
@end
