//
//  DiscountTipTool.m
//  Project
//
//  Created by 包光清 on 2018/8/1.
//

#import "DiscountTipTool.h"

@implementation DiscountTipTool

+ (UILabel *)labelForDealsWithText:(NSString *)text font:(UIFont *)font {
	CGSize size = [DiscountTipTool calculationSizeWithText:text font:font];
	UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, size.width + 2 * font.pointSize, size.height + 0.2 * font.pointSize)];
	label.textAlignment = NSTextAlignmentCenter;
	label.font = font;
	label.text = text;
	label.textColor = [UIColor whiteColor];
	label.backgroundColor = [UIColor redColor];
	label.layer.position = CGPointMake(0, CGRectGetWidth(label.frame) / M_SQRT2);
	label.layer.anchorPoint = CGPointMake(0, 1);
	label.layer.transform = CATransform3DMakeRotation(-M_PI_4, 0, 0, 1);
	return label;
}

+ (CGSize)calculationSizeWithText:(NSString *)text font:(UIFont *)font {
    NSDictionary *attributes = @{NSFontAttributeName:font};
    CGSize size = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attributes context:nil].size;
    return size;
}

@end
