Now I've seen a lot of examples that teach you either how to center the UILabel Text in the middle of the screen, but that's not what I'm asking for. I'm asking on how to make sure that the text of UILabel remains half way between the left and right bounds of the screen and All I have to do is make adjustments Vertically. I have the following:
现在我已经看到很多例子教你如何将UILabel文本居中于屏幕中间,但这并不是我想要的。我想问的是如何确保UILabel的文本保持在屏幕左右边界之间的一半,我所要做的就是垂直调整。我有以下几点:
self.aboutMee = [[UILabel alloc] initWithFrame:CGRectMake(0, 400, 120, self.view.bounds.size.width)];
self.aboutMee.text = @"About Me";
self.aboutMee.textAlignment = NSTextAlignmentCenter;
self.aboutMee.backgroundColor = [UIColor clearColor];
self.aboutMee.font = [UIFont fontWithName:@"Helvetica" size:14];
[self.aboutMee setTextColor:[UIColor colorWithRed:0.0/255.0 green:140.0/255.0 blue:199.0/255.0 alpha:1.0]];
[self.aboutMee setFont:[UIFont fontWithName:@"HelveticaNeueLTStd-ThCn" size:35]];
[self.scrollView addSubview:self.aboutMee];
Now I've tried to make the entire label 320 in width and then just center the text, but that doesn't work. Any ideas?
现在我试着让整个标签宽度为320,然后把文本居中,但这行不通。什么好主意吗?
1 个解决方案
#1
10
You should set frame correctly: CGRectMake(pos.x, pos.y, width, height)
应该正确设置帧:CGRectMake(pos)。x,pos.y、宽度、高度)
self.aboutMee = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
self.aboutMee.text = @"About Me";
self.aboutMee.textAlignment = NSTextAlignmentCenter;
self.aboutMee.backgroundColor = [UIColor clearColor];
self.aboutMee.font = [UIFont fontWithName:@"Helvetica" size:14];
[self.aboutMee setTextColor:[UIColor colorWithRed:0.0/255.0 green:140.0/255.0 blue:199.0/255.0 alpha:1.0]];
[self.aboutMee setFont:[UIFont fontWithName:@"HelveticaNeueLTStd-ThCn" size:35]];
[self.scrollView addSubview:self.aboutMee];
#1
10
You should set frame correctly: CGRectMake(pos.x, pos.y, width, height)
应该正确设置帧:CGRectMake(pos)。x,pos.y、宽度、高度)
self.aboutMee = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
self.aboutMee.text = @"About Me";
self.aboutMee.textAlignment = NSTextAlignmentCenter;
self.aboutMee.backgroundColor = [UIColor clearColor];
self.aboutMee.font = [UIFont fontWithName:@"Helvetica" size:14];
[self.aboutMee setTextColor:[UIColor colorWithRed:0.0/255.0 green:140.0/255.0 blue:199.0/255.0 alpha:1.0]];
[self.aboutMee setFont:[UIFont fontWithName:@"HelveticaNeueLTStd-ThCn" size:35]];
[self.scrollView addSubview:self.aboutMee];