UILabel如何自定义文字位置(左上?右上?左下?右下?)
来源:互联网 发布:唐小曾软件 编辑:程序博客网 时间:2024/04/29 09:14
我们有时候需要在一个Label上显示文字,而该文字的位置位于Label的左上角,我写个一个小Demo,研究了一下。.h文件#import <UIKit/UIKit.h>typedef enum{ VerticalAlignmentTop = 0, VerticalAlignmentMiddle, VerticalAlignmentBottom,} VerticalAlignment;@interface xxxLabel : UILabel@property (nonatomic) VerticalAlignment verticalAlignment;@end.m文件#import "xxxLabel.h"@implementation xxxLabel@synthesize verticalAlignment = verticalAlignment_;- (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.verticalAlignment = VerticalAlignmentMiddle; } returnself;}- (void)setVerticalAlignment:(VerticalAlignment)verticalAlignment { verticalAlignment_ = verticalAlignment; [self setNeedsDisplay];}- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines { CGRect textRect = [super textRectForBounds:bounds limitedToNumberOfLines:numberOfLines]; switch (self.verticalAlignment) { case VerticalAlignmentTop: textRect.origin.y = bounds.origin.y; break; case VerticalAlignmentBottom: textRect.origin.y = bounds.origin.y + bounds.size.height - textRect.size.height; break; case VerticalAlignmentMiddle: default: textRect.origin.y = bounds.origin.y + (bounds.size.height - textRect.size.height) /2.0; } return textRect;}-(void)drawTextInRect:(CGRect)requestedRect { CGRect actualRect = [self textRectForBounds:requestedRect limitedToNumberOfLines:self.numberOfLines]; [super drawTextInRect:actualRect];}@end
0 0
- UILabel如何自定义文字位置(左上?右上?左下?右下?)
- 根据四个点坐标排列出左上右上右下左下位置关系
- 使用LinearLayout线性布局编写左上右上左下右下中央
- android右上、右下、左上、左下手势滑动判断
- 生成水印,可按左上、左下、右上、右下、居中、透明度生成文件
- 生成水印,可按左上、左下、右上、右下、居中、透明度生成文件
- js+css使DIV始终居于屏幕中间 左下 左上 右上 右下的代码集合
- 生成水印,可按左上、左下、右上、右下、居中、透明度生成文件,只对jpeg或jpg格式有效![原创]
- 设置文本框的九种对齐方式(左上,中上,右上,左中,中中,右中,左下,中下,右下)
- 生成水印,可按左上、左下、右上、右下、居中、透明度生成文件,只对jpeg或jpg格式有效!
- 网易编程:寻找所有横,竖,左上到右下,右上到左下,四种方向的所有和
- ViewGroup自定义布局(左上右下)
- [编程题]在一个N*N的数组中寻找所有横,竖,左上到右下,右上到左下,四种方向比较
- 编程题:在一个N*N的数组中寻找所有横,竖,左上到右下,右上到左下,四种方向的直线连续D个数字的和里面最大的值
- iOS 7.0之后的UILabel左上,右下显示
- iOS 7.0之后的UILabel左上,右下显示
- Android背景色渐变(左上->右下)
- 二维数组右上左下遍历
- 这些哭笑不得的情景,每个程序员都可能面对
- PATBasic——1016. 部分A+B (15)
- VS2012 编译clang源码
- Maven实战(四)生命周期
- 修改导航栏上返回按钮上的字,例如把back修改为返回
- UILabel如何自定义文字位置(左上?右上?左下?右下?)
- UITableView全面解析
- Unable to resolve target 'Google Inc.:Google APIs:3'异常
- Maven实战(五)坐标详解
- 微软企业库Unity学习笔记(一)
- scrollview中的实时缩放
- jquery切换select选项 option
- HTTP请求响应状态码详解
- 端口回流与dns-map与域内NAT