BBAFitSizeLabel.h
3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// BBAFitSizeLabel.h
// fontHeight
//
// Created by ZhangJian on 16/9/1.
// Copyright © 2016年 zhangjian. All rights reserved.
//
#import <UIKit/UIKit.h>
extern NSString * fontSizeKey;
extern NSString * textColorKey;
extern NSString * textKey;
extern NSString * imageKey;
/**
*鉴于系统NSAttributedString常常会有一个莫名其妙的边儿,也就是使用boundingRectWithSize计算出来的高度常常有问题在布局里面,包括行与直接的间隔跟实际的像素也是不一样的。所以这里创建了一个类来实现精确的字符串的布局。
*This class is used to calculate the NSAttributedString precisely.
*/
@interface BBAFitSizeLabel : UILabel
/**
* 设置获取取得计算文字真正的到顶部的距离 或者frame等
*/
@property(nonatomic, assign)CGRect pureTextFrame; //逻辑Frame
/**
* 如果你要设置该类的属性,也就是说如果要设置attributedText,必须使用下面的方法生成attributedString你一定要使用下面的方法,而不是自己去创建一个。
* If you want to set attributedString of this, you should use the function below, but not create one attributeString by yourself.
*/
-(NSAttributedString *)makeAnAttributedString:(NSString *)text andLineSpace:(CGFloat)lineSpace andFont:(UIFont*)font andBreakMode:(NSLineBreakMode)lineMode andTextColor:(UIColor *)textColor andWidth:(CGFloat)width andMaxNumberOfLines:(int)lineNumber;
/***
* 计算Size的时候必须使用下面的方法。
* This function is Used To calculate the size of one string.
*/
+(CGSize)sizeThatFit:(NSString *)text andFont:(UIFont *)font andLineSpace:(CGFloat)lineSpace andMaxLinesNumber:(int)lineNumber andFitSize:(CGSize)size;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
+(CGSize)sizeThatFit:(NSArray *)textDicArray andLineSpace:(CGFloat)lineSpace andMaxLinesNumber:(int)lineNumber andFitSize:(CGSize)size;
/**
*textDicArray 是一个由字典组成的数组。
*key分别是
* fontSizeKey(非必须参数);
* textColorKey(非必须参数);
* lineSpaceKey(非必须参数);
* textKey (必需参数);
* imageKey (必需参数);
*/
-(NSAttributedString *)makeAnAttributedString:(NSArray *)textDicArray andLinespace:(CGFloat)linespacet;
// 生成 AttributedString
+ (NSAttributedString *)getAttributedString:(NSString *)text textFont:(UIFont *)font lineSpace:(CGFloat)space;
+ (NSAttributedString *)getAttributedString:(NSString *)text textFont:(UIFont *)font lineSpace:(CGFloat)space lineBreakMode:(NSLineBreakMode)lineBreakMode;
+ (NSAttributedString *)getAttributedString:(NSString *)text textFont:(UIFont *)font lineSpace:(CGFloat)space lineBreakMode:(NSLineBreakMode)lineBreakMode textAlignment:(NSTextAlignment)textAlignment;
+ (NSAttributedString *)getAttributedString:(NSString *)text textFont:(UIFont *)font lineSpace:(CGFloat)space lineBreakMode:(NSLineBreakMode)lineBreakMode textAlignment:(NSTextAlignment)textAlignment textColor:(UIColor *)textColor;
/**
*
* @brief 返回文本行高
*
*/
+ (CGFloat)heightForContent:(NSString *)content lineWidth:(CGFloat)width font:(UIFont *)font maxLines:(NSUInteger)lineCount lineSpaces:(CGFloat)space;
/**
*
* @brief 判断是否为单行文本
*
*/
+ (BOOL)isOneLineText:(NSString *)content font:(UIFont *)font space:(CGFloat)space width:(CGFloat)width;
/**
*
* @brief 单行高度
*
*/
+ (CGFloat)heightForOneLineByFont:(UIFont *)font lineSpace:(CGFloat)space;
@end