//
//  LayoutHelper.m

//
//  Created by xia bob on 5/28/15.

//

#import <Foundation/Foundation.h>
#import "UIHelper.h"

@implementation UIHelper

//根据提供的中心位置，矫正label的frameRect
+(void)setCenter:(UILabel *)label centerX:(int)x centerY:(int)y
{
    CGSize size = [label.text sizeWithAttributes:@{NSFontAttributeName:label.font}];
//    size.width *= 1.0;//中英文都测试过，不需要增加长度
//    size.height *= 1.0;//
    CGRect rect = CGRectMake(x - size.width / 2, y - size.height / 2, size.width, size.height);
    [label setFrame:rect];
}

+(void)setCenter:(UILabel *)label center:(CGPoint)center
{
    [self setCenter:label centerX:center.x centerY:center.y];
}

+(void)setText:(UILabel *)label text:(NSString *)text
{
    CGPoint center = [self getCenter:label.frame];
    label.text = text;
    [self setCenter:label centerX:center.x centerY:center.y];
}

+(CGPoint)getCenter:(CGRect)rect
{
    return CGPointMake(rect.origin.x + rect.size.width / 2, rect.origin.y + rect.size.height / 2);
}

@end
