【发布时间】:2021-11-20 03:16:17
【问题描述】:
我要在目标 c 中创建一个视图,上面有两个标签,label1 有单行,label2 是基于内容的多行。
根据标签中的内容我想调整视图高度,我该怎么做?
视图的宽度应该是屏幕宽度的 20 左右,下面的代码可以纵向显示,但横向显示不正确,它在右侧裁剪。我怎样才能为横向显示正确的 20?
肖像
风景
UIView *emptyTreeView = [[UIView alloc] initWithFrame:CGRectMake(20,20,self.view.frame.size.width - 40,400)];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(30.0, 30.0, self.view.frame.size.width - 100, 30.0)];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(30.0, 90.0, self.view.frame.size.width - 100, 100.0)];
emptyTreeView.backgroundColor=[UIColor blueColor];
label1.backgroundColor = [UIColor redColor];
label1.textAlignment = NSTextAlignmentCenter;
label1.textColor = [UIColor blackColor];
label1.font = [UIFont boldSystemFontOfSize:18];
label1.numberOfLines = 0;
label1.text = @"The Page Cannot be displayed.";
label2.backgroundColor = [UIColor whiteColor];
label2.textAlignment = NSTextAlignmentCenter;
label2.textColor = [UIColor grayColor];
label2.font = [UIFont systemFontOfSize:15];
label2.numberOfLines = 0;
label2.text = @"Please use this feature or contact your internal contact person directly.";
[emptyTreeView addSubview:label1];
[emptyTreeView addSubview:label2];
[self.view addSubview:emptyTreeView];
我做错了什么吗?
【问题讨论】:
-
@Rob 我已经用您建议的更改更新了我的问题,但它没有按预期工作,您可以检查一次。
标签: ios objective-c uiview