requires iOS 6.0+.
1.Add pod 'DFLabelSizeFit' to your Podfile.
2.Run pod install or pod update.
3.import "DFLabelSizeFit.h"
1.Download all the files in the DFLabelSizeFit subdirectory.
2.Add the DFLabelSizeFit group to your Xcode project.
3.import "DFLabelSizeFit.h
- use these methods you should set label's frame at first.
1.single line text. the label height you get is the fontsize.According textAlignment set label's frame.
- (UILabel *)df_labelSizeFit;
2.single line text.only fit width. the label height you get is the frame.size.height you set.
- (UILabel *)df_labelSizeFitKeepOldHeight;
3. Multiline text in one paragraph.
@param lineSpacing lineSpacing
@param singleLineKeepWidth when single line,keep width you set or get the actual label width.
- (UILabel *)df_labelSizeFitWithLineSpacing:(CGFloat)lineSpacing
singleLineKeepWidth:(BOOL)singleLineKeepWidth;
4. muti paragraph.
@param lineSpacing lineSpacing
@param paragraphSpacingBefore paragraphSpacingBefore
@param alignment alignment
@param isFirstLineHeadIndent isFirstLineHeadIndent
- (UILabel *)df_labelSizeFitWithLineSpacing:(CGFloat)lineSpacing
paragraphSpacingBefore:(CGFloat)paragraphSpacingBefore
alignment:(NSTextAlignment)alignment
isFirstLineHeadIndent:(BOOL)isFirstLineHeadIndent;
provided under the MIT license. See LICENSE file for details.
最低支持 iOS 6.0
1.在 Podfile 中添加 pod 'DFLabelSizeFit'。
2.执行 pod install 或 pod update。
3.导入 "DFLabelSizeFit.h"。
1.下载 DFLabelSizeFit 文件夹内的所有内容。
2.将 DFLabelSizeFit文件夹添加(拖放)到你的工程。
3.import "DFLabelSizeFit.h"
- 使用这些方法前你需要先设置label的frame
1.单行。返回label高度是font值的pointSize。并根据textAlignment设置label的位置。
- (UILabel *)df_labelSizeFit;
2.单行。自适应宽。返回高为你设置的frame的height
- (UILabel *)df_labelSizeFitKeepOldHeight;
3. 多行
@param lineSpacing 行距
@param keepWidth 文字单行时是保持设置的frame的width还是返回实际的label的width
- (UILabel *)df_labelSizeFitWithLineSpacing:(CGFloat)lineSpacing
singleLineKeepWidth:(BOOL)singleLineKeepWidth;
4. 多段落设置富文本
@param lineSpacing 行距
@param paragraphSpacingBefore 段落之间的间距
@param alignment 对齐方式
@param isFirstLineHeadIndent 首行是否缩进两字符
- (UILabel *)df_labelSizeFitWithLineSpacing:(CGFloat)lineSpacing
paragraphSpacingBefore:(CGFloat)paragraphSpacingBefore
alignment:(NSTextAlignment)alignment
isFirstLineHeadIndent:(BOOL)isFirstLineHeadIndent;
使用 MIT 许可证,详情见LICENSE 文件。
qq交流群:479873475
合作qq:188816190