1
我是IOS的新手,需要一些幫助。我有行的元素,每行都從一個數組中填充,行被排列成一個在另一個下面。行由標籤和標籤需要具有不同的顏色。此代碼將顏色應用於單個標籤的整行。一行中各個標籤的着色
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 240)];
int bx=0;
for (NSString * str1 in arr1)
{
if ([arr1 count]<=2) {
label=[[UILabel alloc]initWithFrame:CGRectMake(bx, -1, scrollView.frame.size.width/[arr1 count], 100)];
label.textAlignment=NSTextAlignmentCenter;
}
else
{
label=[[UILabel alloc]initWithFrame:CGRectMake(bx, -1, 106, 100)];
label.textAlignment=NSTextAlignmentCenter;
}
[label setText:[NSString stringWithFormat:@"(%@)",str1]];
[scrollView addSubview:label];
bx +=label.frame.size.width;
}