Sek*_*har 0 iphone xcode objective-c uilabel ios
我想在我的数组中添加与对象一样多的标签.但是如何对齐它们?我想要一个低于另一个,并且id已经完成,它应该在下一列开始.但是我尝试将其覆盖另一个代码.
- (void)viewDidLoad
{
[super viewDidLoad];
array = [[ NSMutableArray alloc]initWithObjects:@"aaa",@"bbb",@"ccc",@"ddd",nil];
for( int i=0;i<[array count];i++)
{
NSString *theText = [array lastObject];
UILabel *label = [[UILabel alloc]init];
label.text = theText;
label.backgroundColor = [UIColor clearColor];
label.lineBreakMode = UILineBreakModeWordWrap;
label.frame = CGRectMake(0, label.frame.origin.y + label.frame.size.height, size.width + 20, size.height + 20);
[self.view addSubview:label];
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
试试这个代码..
array = [[ NSMutableArray alloc]initWithObjects:@"aaa",@"bbb",@"ccc",@"ddd",nil];
UILabel *label;
int y =10;
for( int i=0;i<[array count];i++)
{
NSString *theText = [array objectAtIndex:i];
label = [[UILabel alloc]init];
label.text = theText;
label.backgroundColor = [UIColor clearColor];
label.frame = CGRectMake(0, y + label.frame.size.height, size.width + 20, size.height + 20);
[self.view addSubview:label];
y = y +label.frame.size.height+5;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1475 次 |
| 最近记录: |