DFLabelSizeFit使用方法

DFLabelSizeFit

     

one line of code to fit label size.(一行代码自适应label size)

->DFLabelSizeFit github地址



system Requirements

requires iOS 6.0+.

Installation

CocoaPods
1
2
3
Add pod 'DFLabelSizeFit' to your Podfile.
Run pod install or pod update.
import "DFLabelSizeFit.h"
Manually
1
2
3
Download all the files in the DFLabelSizeFit subdirectory.
Add the DFLabelSizeFit group to your Xcode project.
import "DFLabelSizeFit.h"

Document

  • 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.

1
- (UILabel *)df_labelSizeFit;


2.single line text.only fit width. the label height you get is the frame.size.height you set.

1
- (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.

1
2
- (UILabel *)df_labelSizeFitWithLineSpacing:(CGFloat)lineSpacing
singleLineKeepWidth:(BOOL)singleLineKeepWidth;


4. muti paragraph.

@param lineSpacing lineSpacing

@param paragraphSpacingBefore paragraphSpacingBefore

@param alignment alignment

@param isFirstLineHeadIndent isFirstLineHeadIndent

1
2
3
4
- (UILabel *)df_labelSizeFitWithLineSpacing:(CGFloat)lineSpacing
paragraphSpacingBefore:(CGFloat)paragraphSpacingBefore
alignment:(NSTextAlignment)alignment
isFirstLineHeadIndent:(BOOL)isFirstLineHeadIndent;

License

provided under the MIT license. See LICENSE file for details.



中文介绍

系统要求

最低支持 iOS 6.0

安装

CocoaPods
1
2
3
在 Podfile 中添加 pod 'DFLabelSizeFit'。
执行 pod install 或 pod update。
导入 "DFLabelSizeFit.h"。
手动安装
1
2
3
下载 DFLabelSizeFit 文件夹内的所有内容。
将 DFLabelSizeFit文件夹添加(拖放)到你的工程。
import "DFLabelSizeFit.h"

文档

  • 使用这些方法前你需要先设置label的frame

    1.单行。返回label高度是font值的pointSize。并根据textAlignment设置label的位置。
    1
    - (UILabel *)df_labelSizeFit;


2.单行。自适应宽。返回高为你设置的frame的height

1
- (UILabel *)df_labelSizeFitKeepOldHeight;


3. 多行

@param lineSpacing 行距

@param keepWidth 文字单行时是保持设置的frame的width还是返回实际的label的width

1
2
- (UILabel *)df_labelSizeFitWithLineSpacing:(CGFloat)lineSpacing
singleLineKeepWidth:(BOOL)singleLineKeepWidth;


4. 多段落设置富文本

@param lineSpacing 行距

@param paragraphSpacingBefore 段落之间的间距

@param alignment 对齐方式

@param isFirstLineHeadIndent 首行是否缩进两字符

1
2
3
4
- (UILabel *)df_labelSizeFitWithLineSpacing:(CGFloat)lineSpacing
paragraphSpacingBefore:(CGFloat)paragraphSpacingBefore
alignment:(NSTextAlignment)alignment
isFirstLineHeadIndent:(BOOL)isFirstLineHeadIndent;

许可证

使用 MIT 许可证,详情见LICENSE 文件。

THANKS!


qq交流群:479873475

合作qq:188816190