豫剧花木兰从军
iOS⾃定义UILabel可以使⽂字居上居中居下
前⾔:做过iOS 的都知道,UILabel有让⽂字居左,居右,居中的属性,可是有时候我们在做项⽬的时候,可能会需要将label上的⽂字居上, 居中或者 居下这样的操作。那么今天我们就来说⼀说这种效果的实现⽅式。
#import <UIKit/UIKit.h>
typedefenum
{
谢谢老板表情包VerticalAlignmentTop =0,// default
VerticalAlignmentMiddle,
宁波小吃VerticalAlignmentBottom,
} VerticalAlignment;
@interfaceBaUILabel :UILabel
{
@private
VerticalAlignment_verticalAlignment;
}
@property(nonatomic)VerticalAlignmentverticalAlignment;
@end
达克宁多少钱#import"BaUILabel.h"
@implementationBaUILabel
@synthesizeverticalAlignment =verticalAlignment_;
- (id)initWithFrame:(CGRect)frame {
if(lf= [superinitWithFrame:frame]) {
lf.verticalAlignment=VerticalAlignmentMiddle;戏答
}
returnlf;
}
- (void)tVerticalAlignment:(VerticalAlignment)verticalAlignment {
verticalAlignment_= verticalAlignment;
[lftNeedsDisplay];
}
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines { CGRecttextRect = [supertextRectForBounds:boundslimitedToNumberOfLines:numberOfLines];
switch(lf.verticalAlignment) {
caVerticalAlignmentTop:
break;
caVerticalAlignmentBottom:
break;
caVerticalAlignmentMiddle:
小熊猫车// Fall through.
default:
骑行新藏线}
returntextRect;
}
桃树嫁接时间和方法-(void)drawTextInRect:(CGRect)requestedRect {
CGRectactualRect = [lftextRectForBounds:requestedRectlimitedToNumberOfLines:lf.numberOfLines]; [superdrawTextInRect:actualRect];
}
@end
这样我们在使⽤的时候,只要继承这个label类,然后选择想要实现效果的属性即可