iOSUILable边距设置
来源:互联网 发布:java和java大数据区别 编辑:程序博客网 时间:2024/05/22 04:27
在iOS中Lable是没有 UIEdgeInsets这个属性可以调用的,那么我们想修改下Lable的上下左右的边距该怎么办呢?例如:
那么现在来实现下,代码如下:
1.首先创建一个继承UILable的类
2.增加 UIEdgeInsets属性
#import <UIKit/UIKit.h>@interface customBaseLab : UILabel/** * lable文字的边距 */@property (nonatomic, assign) UIEdgeInsets textLableInsets;@end3..m实现如下:
- (instancetype)init { if (self = [super init]) { _textInsets = UIEdgeInsetsZero; } return self;}- (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { _textInsets = UIEdgeInsetsZero; } return self;}- (void)drawTextInRect:(CGRect)rect { [super drawTextInRect:UIEdgeInsetsInsetRect(rect, _textInsets)];}是不是很简单呢 哈哈 !!!!
使用实例:
customBaseLab *yearLab = [[customBaseLab alloc] initWithFrame:CGRectMake(0, 0, self.viewWidth-30, self.viewHeight)]; yearLab.backgroundColor = [UIColor whiteColor]; yearLab.text = @"2012"; yearLab.textColor = [UIColor grayColor]; yearLab.font = [UIFont systemFontOfSize:16.0f]; yearLab.textInsets = UIEdgeInsetsMake(0, 15, 0, 0);//调用 [self.view addSubview: yearLab];技术有限 就到这,请大神多多指点;转载请注明出处,谢谢!!!
1 0
- iOSUILable边距设置
- 设置纸张边距
- html边距设置
- css边距设置
- ReportViewer 的边距设置
- GridView item 设置边距
- DrawerLayout设置滑动边距
- DrawerLayout设置滑动边距
- RecyclerView优雅设置边距
- c#的excel边距设置
- MyEclipse 设置行打印边距
- 表格的边距 边框设置
- c# RichTextBox 垂直居中 边距设置
- iOS UITextView以设置边距
- iOS 设置label的边距
- ListView divider设置两边边距
- 通过margin设置边距属性 通过border设置边距属性
- 动态添加布局并且设置子布局水平居中,设置边距
- MySQL start and stop
- MyEclipse-2015-Stable-3.0破解
- PHP的垃圾回收机制
- HTML input="file" 浏览时只显示指定文件类型 xls、xlsx、csv
- My First In CSDN
- iOSUILable边距设置
- benchmark学习笔记
- 生成按色调饱和度排列的BMP位图
- VLC player_KVO监听
- 如何自动添加dcos的节点(非安装方法)
- Android中扫描多媒体文件操作详解
- Loadrunner监控windows系统“找不到网络路径”问题解决
- error: No resource identifier found for attribute 'cardCornerRadius' in package 'com.example.test'
- 常见的css兼容性问题---持续更新!!