【发布时间】:2020-01-10 16:12:17
【问题描述】:
以编程方式创建滚动视图,然后添加标签。
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:scrollView];
然后标注
UILabel *errLabel = [[UILabel alloc] init];
errLabel.text = @"Top Label";
//errLabel.frame = CGRectMake(self.view.frame.size.width/2,50,120,20);
errLabel.frame = CGRectMake(CGRectGetWidth(scrollView.frame)/2.00,50,120,20);
errLabel.textAlignment = NSTextAlignmentCenter;
errLabel.layer.borderColor = [UIColor grayColor].CGColor;
errLabel.layer.borderWidth = 3.0;
[errLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
[scrollView addSubview:errLabel];
在 iPhone 8、11 Pro Max 和最大 iPad 的模拟器中,标签位于中心右侧。这是 iOS 11 的错误还是我遗漏了什么?
【问题讨论】:
-
PS - 插入我的 iPhone 并在其上进行测试 - 仍然在中心右侧....
标签: objective-c xcode uiscrollview position uilabel