2014-03-14 4 views
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; 
} 

답변

0

는 단순히

label.backgroundColor = [UIColor redColor]; 

넣어 자신의 backgroundColor enter code here 속성을 사용 UILabel에 배경 색상을 지정할 수 있습니다 당신이 다음있는 UITableViewCell에 differnt 한 색상을 적용 할 경우 라벨을

1

를 초기화 한 후, 다른 색상을 저장하기위한 배열을 가져옵니다.

UITABLEVIEWDATASOURCE 방법에서

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
// init your cell. 

// use below if you have specific number of cells. 
[cell.backgroundcolor = [colorarray object at index: indexpath.row]]; 

or you can do below if it`s suitable to you. 
if([indexpath.row % 2 == 0]) 
{ 
[cell.backgroundcolor = [uicolor your color]]; 
} 

else 
{ 
[cell.backgroundcolor = [uicolor your different color]]; 
} 



} 
관련 문제