UIlabel顶格
来源:互联网 发布:淘宝店信誉怎么提高 编辑:程序博客网 时间:2024/05/16 17:33
新建一个继承uilabel的类,用它定义label,设置属性即可。
#import <UIKit/UIKit.h>
typedefenum : NSUInteger {
VerticalAlignmentTop =0, // default
VerticalAlignmentMiddle,
VerticalAlignmentBottom,
} VerticalAlignment;
@interface MyLabel :UILabel
@property (nonatomic)VerticalAlignment verticalAlignment;
@end
#import "MyLabel.h"
@implementation MyLabel
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame {
if (self = [superinitWithFrame:frame]) {
self.verticalAlignment =VerticalAlignmentMiddle;
}
return self;
}
- (void)setVerticalAlignment:(VerticalAlignment)verticalAlignment {
_verticalAlignment = verticalAlignment;
[selfsetNeedsDisplay];
}
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines {
CGRect textRect = [supertextRectForBounds:bounds limitedToNumberOfLines:numberOfLines];
switch (self.verticalAlignment) {
caseVerticalAlignmentTop:
textRect.origin.y = bounds.origin.y;
break;
caseVerticalAlignmentBottom:
textRect.origin.y = bounds.origin.y + bounds.size.height - textRect.size.height;
break;
caseVerticalAlignmentMiddle:
// Fall through.
default:
textRect.origin.y = bounds.origin.y + (bounds.size.height - textRect.size.height) /2.0;
}
return textRect;
}
-(void)drawTextInRect:(CGRect)requestedRect {
CGRect actualRect = [selftextRectForBounds:requestedRect limitedToNumberOfLines:self.numberOfLines];
[superdrawTextInRect:actualRect];
}
@end
实现:
- (void)awakeFromNib{
[self.titleLabelsetVerticalAlignment:VerticalAlignmentTop];
}
- UIlabel顶格
- UITableViewCell 分割线顶格
- UILabel
- UILabel
- UILabel
- UILabel
- UILabel
- UILabel
- UILabel
- UILabel
- UILabel
- UILabel
- UILabel
- UILabel
- UILabel
- UIlabel
- UILabel
- UILabel
- MFC dll 与 boost 静态库的兼容性问题
- 转载博文
- java 运算符
- 怎样解决Java/J2EE中文问题
- ABAP中读取文本文件(TXT DOCUMENT)并用ALV显示
- UIlabel顶格
- eclipse 打开源文件左侧自动展现对应的文件夹,能选中源文件
- JPA hibernate 基于注解的级联
- IMP-00013 问题及解决方法
- UIFontWDCustomLoader
- 30-40岁的程序员们,请把一些账算清楚,为过冬做准备(二)
- 语音特征参数MFCC计算的详细过程
- Java 通过JDBC连接Mysql数据库的方法和实例
- adt配置支持html5的移动web app开发环境