它無法對齊文本中UILabel
垂直。但是,您可以使用sizeWithFont:
方法NSString
動態更改標籤的高度,只需根據需要設置它的x和y即可。
作爲替代方案,您可以使用UITextField
。它支持contentVerticalAlignment
屬性,因爲它是UIControl
的子類。您必須將其userInteractionEnabled
設置爲NO
以防止用戶在其上鍵入文本。
EDIT 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];
這不稱爲對齊,這被稱爲書寫方向。對齊是完全不同的。僅供參考我不認爲有實現你想要的方法。也許使用CoreText和CoreGraphics,你可以像這樣畫一個CFStringRef,但不能使用UILabel。 – 2012-10-20 07:29:11
嗨,使用我的答案這是工作好了。請使用參考 – 2012-10-20 07:57:40