iOS自定义UILabel可以使文字居上居中居下

更新时间:2023-05-29 19:53:30 阅读: 评论:0

iOS⾃定义UILabel可以使⽂字居上居中居下
前⾔:做过iOS 的都知道,UILabel有让⽂字居左,居右,居中的属性,可是有时候我们在做项⽬的时候,可能会需要将label上的⽂字居上, 居中或者 居下这样的操作。那么今天我们就来说⼀说这种效果的实现⽅式。fag
#import <UIKit/UIKit.h>
typedefenum
ertl{
VerticalAlignmentTop =0,// default
美容美发培训学校VerticalAlignmentMiddle,
VerticalAlignmentBottom,
} VerticalAlignment;
@interfaceBaUILabel :UILabel
{
@private
VerticalAlignment_verticalAlignment;
wonderful
}
@property(nonatomic)VerticalAlignmentverticalAlignment;
soup怎么读@end
#import"BaUILabel.h"
@implementationBaUILabel
peace of mind@synthesizeverticalAlignment =verticalAlignment_;
- (id)initWithFrame:(CGRect)frame {
nice是什么中文意思
zoroif(lf= [superinitWithFrame:frame]) {
lf.verticalAlignment=VerticalAlignmentMiddle;
}
returnlf;
}
- (void)tVerticalAlignment:(VerticalAlignment)verticalAlignment {
verticalAlignment_= verticalAlignment;
[lftNeedsDisplay];
pool是什么意思}
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines { CGRecttextRect = [supertextRectForBounds:boundslimitedToNumberOfLines:numberOfLines];
switch(lf.verticalAlignment) {
caVerticalAlignmentTop:
break;
caVerticalAlignmentBottom:
break;glbt
caVerticalAlignmentMiddle:
// Fall through.
default:
}
returntextRect;
}
-(void)drawTextInRect:(CGRect)requestedRect {
CGRectactualRect = [lftextRectForBounds:requestedRectlimitedToNumberOfLines:lf.numberOfLines]; [superdrawTextInRect:actualRect];
}
@end
这样我们在使⽤的时候,只要继承这个label类,然后选择想要实现效果的属性即可

本文发布于:2023-05-29 19:53:30,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/127342.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:时候   居中   居下   效果   实现   学校
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图