现在,我已经看到了很多示例,这些示例可以教您如何将UILabel Text居中显示在屏幕中间,但这不是我要的。我在询问如何确保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];
现在,我尝试将整个标签的宽度设置为320,然后将文本居中放置,但这不起作用。有任何想法吗?
您应该正确设置框架:CGRectMake(pos.x,pos.y,width,height)
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];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句