它不可能UILabel
垂直对齐文本。sizeWithFont:
但是,您可以使用of 方法动态更改标签的高度NSString
,并根据需要设置其 x 和 y。
作为替代方案,您可以使用UITextField
. 它支持contentVerticalAlignment
peoperty,因为它是UIControl
. 您必须将其设置userInteractionEnabled
为NO
以防止用户在其上键入文本。
编辑 1
好吧,而不是 UILabel ,制作一个 UITableView 像:-
TableActivityLevel=[[UITableView alloc] initWithFrame:CGRectMake(224, 203, 27, 0) style:UITableViewStylePlain];
TableActivityLevel.delegate=self;
TableActivityLevel.dataSource=self;
TableActivityLevel.autoresizingMask = UIViewAutoresizingFlexibleHeight;
TableActivityLevel.rowHeight = 17;
TableActivityLevel.backgroundColor=[UIColor clearColor];
TableActivityLevel.layer.borderColor = [[UIColor clearColor]CGColor];
TableActivityLevel.separatorStyle = UITableViewCellSeparatorStyleNone;
编辑 2也找到了使用 UILabels 的方法!:) 看一下这个....
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 10.0, 100.0)];
[label1 setBackgroundColor:[UIColor clearColor]];
[label1 setNumberOfLines:0];
[label1 setCenter:self.view.center];
[label1 setFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
[label1 setTextColor:[UIColor whiteColor]];
[label1 setTextAlignment:UITextAlignmentCenter];
[label1 setText:@"1 2 3 4 5 6"];
[self.view addSubview:label1];