美文网首页
ios自适应

ios自适应

作者: HMZ4978 | 来源:发表于2017-08-20 13:00 被阅读0次

一,    label适应文字多少

UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(40, 100, WIDTH-80, 50)];

lab.textColor = [UIColor blackColor];

lab.layer.borderWidth = 2;

lab.layer.borderColor = [UIColor redColor].CGColor;

// label 适应文字大小多少

[lab szieAdaptiveWithText:@"323.45" andTextFont:[UIFont systemFontOfSize:30] andTextMaxSzie:CGSizeMake(5, 5)];

[self.view addSubview:lab];


UILabel *lab1 = [[UILabel alloc] initWithFrame :CGRectMake(40, 200, WIDTH-80, 50)];

lab1.textColor = [UIColor blackColor];

lab1.layer.borderWidth = 2;

lab1.layer.borderColor = [UIColor redColor].CGColor;

[lab1 szieAdaptiveWithText:@"323.45affafda" andTextFont:[UIFont systemFontOfSize:30] andTextMaxSzie:CGSizeMake(5, 5)];

[self.view addSubview:lab1];


UILabel *lab2 = [[UILabel alloc] initWithFrame:CGRectMake(40, 300, WIDTH-80, 50)];

lab2.textColor = [UIColor blackColor];

lab2.layer.borderWidth = 2;

lab2.layer.borderColor = [UIColor redColor].CGColor;

[lab2 szieAdaptiveWithText:@"这是测试的文字这是测试的文字" andTextFont:[UIFont systemFontOfSize:30] andTextMaxSzie:CGSizeMake(5, 5)];

lab2.textAlignment = NSTextAlignmentLeft;

[self.view addSubview:lab2];


二,  文字适应固定大小的label

效果图片

UILabel *progress_text = [[UILabel alloc] initWithFrame: CGRectMake(20, 100, 300, 50)];

progress_text.backgroundColor = [UIColor blackColor];

progress_text.text = @"人生难免经历苦痛挣扎🐂🐂🐂°°°°°°°°°°°°挣扎🐂🐂";

progress_text.textColor = [UIColor whiteColor];

progress_text.adjustsFontSizeToFitWidth = YES;

progress_text.textAlignment = NSTextAlignmentCenter;

progress_text.font = [UIFont systemFontOfSize:20];

[self.view addSubview: progress_text];


UILabel *progress_text2 = [[UILabel alloc] initWithFrame: CGRectMake(20, 200, 300, 50)];

progress_text2.backgroundColor = [UIColor blackColor];

progress_text2.text = @"人生难免经历苦痛挣扎人生难免经历苦痛挣扎";

progress_text2.textColor = [UIColor whiteColor];

progress_text2.adjustsFontSizeToFitWidth = YES;

progress_text2.textAlignment = NSTextAlignmentCenter;

progress_text2.font = [UIFont systemFontOfSize:20];

[self.view addSubview: progress_text2];


UILabel *progress_text3 = [[UILabel alloc] initWithFrame: CGRectMake(20, 300, 300, 50)];

progress_text3.backgroundColor = [UIColor blackColor];

progress_text3.text = @"人生难免经历苦痛挣扎人生难免经历苦痛挣扎人生难免经历苦痛挣扎";

progress_text3.textColor = [UIColor whiteColor];

progress_text3.adjustsFontSizeToFitWidth = YES;

progress_text3.textAlignment = NSTextAlignmentCenter;

progress_text3.font = [UIFont systemFontOfSize:20];

[self.view addSubview: progress_text3];


UILabel *progress_text4 = [[UILabel alloc] initWithFrame: CGRectMake(20, 400, 300, 50)];

progress_text4.backgroundColor = [UIColor blackColor];

progress_text4.text = @"人生难免经历苦痛挣扎人生难免经历苦痛挣扎人生难免经历苦痛挣扎扎";

progress_text4.numberOfLines = 0;

progress_text4.textColor = [UIColor whiteColor];

progress_text4.adjustsFontSizeToFitWidth = YES;

progress_text4.textAlignment = NSTextAlignmentCenter;

progress_text4.font = [UIFont systemFontOfSize:20];

[self.view addSubview: progress_text4];

相关文章

网友评论

      本文标题:ios自适应

      本文链接:https://www.haomeiwen.com/subject/qfgorxtx.html