文本自适应(sizeToFit)
来源:互联网 发布:我的世界手机版火车js 编辑:程序博客网 时间:2024/04/28 04:55
@interface ViewController ()
@property (nonatomic,strong) UITextField *textFile;
@property (nonatomic,strong) UILabel *label;
@end
- (void)viewDidLoad{
//1.获得主屏幕的宽和高
CGFloat screeW = [UIScreenmainScreen].bounds.size.width;
CGFloat screeH = [UIScreenmainScreen].bounds.size.height;
//textFile
//比例布局
UITextField *textFile = [[UITextFieldalloc] initWithFrame:CGRectMake(screeW *0.125, screeH * 0.15, screeW *0.75, screeH * 0.055)];
//设置文本输入框的边框模式
textFile.borderStyle =UITextBorderStyleBezel;
//通过通知实时监测textFile里面的值
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(changeTextFile)name:UITextFieldTextDidChangeNotificationobject:nil];
self.textFile = textFile;
//设置文体大小
textFile.font = [UIFontsystemFontOfSize:20];
//设置字体颜色
textFile.textColor = [UIColorblackColor];
[self.viewaddSubview:textFile];
//label
//比例布局
UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(screeW *0.125, screeH * 0.25,100, 50)];
//label背景颜色
label.backgroundColor = [UIColorlightGrayColor];
//字体颜色
label.textColor = [UIColorwhiteColor];
//字体大小
label.font = [UIFontsystemFontOfSize:20];
//_label.numberOfLines = 0;一旦加了这句话,文本的自适应回事宽度不变,高度变,否则就是高度不变,宽度变
self.label = label;
[self.viewaddSubview:label];
//按钮
UIButton *button = [[UIButtonalloc] initWithFrame:CGRectMake(screeW *0.125, screeH * 0.35, screeW * 0.75, screeH *0.055)];
// 添加按钮标题
[button setTitle:@"自适应文本"forState:UIControlStateNormal];
//文字颜色
[button setTitleColor:[UIColorwhiteColor] forState:UIControlStateNormal];
//按钮背景颜色
button.backgroundColor = [UIColorbrownColor];
//添加按钮点击事件
[button addTarget:selfaction:@selector(btnEvent)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
}
- (void)changeTextFile{
self.label.text =self.textFile.text;
}
- (void)btnEvent{
[self.labelsizeToFit];
}
- 文本自适应(sizeToFit)
- sizeToFit (自适应UILable的大小)
- UILabel文字大小自适应之--SizeToFit
- UILabel文字大小自适应之--SizeToFit
- UILabel文字大小自适应之--SizeToFit
- sizeToFit
- sizeToFit 解决Label的高度自适应碰到的一些问题
- 文本自适应高度(含适配iOS7)
- UILabel实现文本自适应方法(ios7)
- UILabel自适应文本,让文本自适应
- webview 文本 自适应 高度
- IOS文本自适应高度
- 文本自适应高度
- Label文本内容自适应
- ios富文本自适应
- 单元格文本自适应
- 未知文本自适应居中
- UILable sizeToFit
- 第12章课后第5题答案
- 大二前期工作计划以及近期具体安排
- 如何选择开源许可证
- 逗号运算符
- update
- 文本自适应(sizeToFit)
- 二分排序算法
- Android Audio Effect 机制初探
- 滴滴出行918编程
- 数据存储总结
- Self Crossing
- word2Vec浅析
- Siemens NX 8.5
- caffe中batch_norm层代码详细注解