效果图:
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnL2QDNwEDOxETM5ITOwAjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
1、主要用到了两个方法和一个工具类ZWMaker
-
-(CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines;
-
-(void)drawTextInRect:(CGRect)requestedRect
2、对齐类型
typedef NS_ENUM(NSUInteger, TextAlignType) {
TextAlignType_top = 1, // 顶部对齐
TextAlignType_left, // 左边对齐
TextAlignType_bottom, // 底部对齐
TextAlignType_right, // 右边对齐
TextAlignType_center // 水平/垂直对齐(默认中心对齐)
};
3、调用方式
[label textAlign:^(ZWMaker *maker) {
make.addAlignType(TextAlignType_bottom).addAlignType(TextAlignType_center);
}];
[label textAlign:^(ZWMaker *maker) {
maker.bottom().center();
}];
项目地址:https://github.com/MisterZhouZhou/UILabelTextAlign