
- Removed YuMi/Library/ (138 MB, not tracked) - Removed YuMi/Resources/ (23 MB, not tracked) - Removed old version assets (566 files, not tracked) - Excluded Pods/, xcuserdata/ and other build artifacts - Clean repository optimized for company server deployment
71 lines
1.6 KiB
Objective-C
71 lines
1.6 KiB
Objective-C
//
|
|
// UILabel+Utils.m
|
|
// YuMi
|
|
//
|
|
// Created by duoban on 2023/7/14.
|
|
//
|
|
|
|
#import "UILabel+Utils.h"
|
|
|
|
@implementation UILabel (Utils)
|
|
+(UILabel *)labelInitWithText:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor{
|
|
UILabel *label = [[UILabel alloc]initWithFrame:CGRectZero];
|
|
if(text.length > 0){
|
|
label.text = text;
|
|
}
|
|
if(font != nil){
|
|
label.font = font;
|
|
}
|
|
if(textColor != nil){
|
|
label.textColor = textColor;
|
|
}
|
|
return label;
|
|
}
|
|
/**
|
|
根据宽度求高度
|
|
@param text 计算的内容
|
|
@param width 计算的宽度
|
|
@param font font字体大小
|
|
@return 放回label的高度
|
|
*/
|
|
|
|
+ (CGFloat)getLabelHeightWithText:(NSString *)text width:(CGFloat)width font: (UIFont *)font
|
|
|
|
{
|
|
|
|
CGRect rect = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
|
|
|
|
options:NSStringDrawingUsesLineFragmentOrigin
|
|
|
|
attributes:@{NSFontAttributeName:font} context:nil];
|
|
|
|
|
|
|
|
return rect.size.height;
|
|
|
|
}
|
|
/**
|
|
根据高度求宽度
|
|
@param text 计算的内容
|
|
@param height 计算的高度
|
|
@param font font字体大小
|
|
@return 返回Label的宽度
|
|
*/
|
|
|
|
+ (CGFloat)getWidthWithText:(NSString *)text height:(CGFloat)height font:(UIFont *)font{
|
|
|
|
|
|
|
|
CGRect rect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, height)
|
|
|
|
options:NSStringDrawingUsesLineFragmentOrigin
|
|
|
|
attributes:@{NSFontAttributeName:font}
|
|
|
|
context:nil];
|
|
|
|
return rect.size.width;
|
|
|
|
}
|
|
@end
|