2012-10-19 5 views
1

네비게이션 컨트롤러에 테이블 뷰가 있습니다. 표보기의 셀은 원본보다 너비가 작고 배경은 이미지입니다. "선택한 색상"을 어떻게 설정할 수 있습니까?UITableViewCell 너비

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 


    static NSString *CellIdentifier = @"ApplicationCell"; 

    ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[CompositeSubviewBasedApplicationCell alloc] initWithStyle:UITableViewCellStyleDefault 
                  reuseIdentifier:CellIdentifier]; 



    } 
return cell; 
} 


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) 
    { 
     cellContentView = [[CompositeSubviewBasedApplicationCellContentView alloc] initWithFrame:CGRectInset(self.contentView.bounds, 0.0, 1.0) cell:self]; 
     cellContentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     cellContentView.contentMode = UIViewContentModeRedraw; 

     //here i'm making the cells smaller in width than the rest of the tableView 
     CGRect framme = cellContentView.frame; 

     framme.size.width = framme.size.width-58; 
     //set the left space 
     framme.origin.x = framme.origin.x+29; 

     [cellContentView setFrame:framme]; 
     [self.contentView addSubview:cellContentView]; 
    } 
    return self; 
} 

here is my table view unselected

selected

답변

2

TableViewCell의이 backgroundViewselectedBackgroundView이 : 여기에 지금까지 내 코드입니다. 이러한 배경을 배경으로 사용하고 레이블 및 이미지보기 만 contentView에 넣습니다. Madboy도 backgroundView와 selectedBackgroundView는 그 속성대로 논문의 속성으로 재생할 수있다 그것 때문에 언급 한 바와 같이 당신의 backgroundColor 등 처럼의 모든 UIView의 클래스 속성을 사용할 수 있도록

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) 
    { 
     UIView* backgroundView = [[UIView alloc] initWithFrame:self.bounds]; 
     UIView* visibleBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(29.0f, 0.0f, backgroundView.bounds.size.width - 58.0f, backgroundView.bounds.size.height)]; 
     // configure the visibleBackgroundView with the color you want for unselected cell here 
     [backgroundView addSubview:visibleBackgroundView]; 
     self.backgroundView = backgroundView; 

     UIView* selectedBackgroundView = [[UIView alloc] initWithFrame:self.bounds]; 
     UIView* visibleSelectedBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(29.0f, 0.0f, backgroundView.bounds.size.width - 58.0f, backgroundView.bounds.size.height)]; 
     // configure the visibleSelectedBackgroundView with the color you want for selection here 
     [selectedBackgroundView addSubview:visibleSelectedBackgroundView]; 
     self.selectedBackgroundView = selectedBackgroundView; 

     // configure your content view with all the labels you need here 
    } 
    return self; 
} 
+0

괜찮 았지만 선택한 프레임이 더 작은 프레임이 아닙니다. – Filip

+0

아니요, 전체 크기 인'selectedBackgroundView'를 설정 한 다음, 예제에서와 같이 적절한 크기를 가진 backgroundView에 하위 뷰를 추가해야합니다. 이것은 또한'backgroundView' 속성으로 무엇을 해야하는지입니다. –

+0

아하 그것을 가지고 그것을 시도하고 알려 드리겠습니다! 당신의 도움을 많이 주셔서 고마워요 – Filip

1

있는 UITableViewCell이있는 UIView의 서브 클래스입니다 맞춤 설정된 셀로 만드십시오.

+0

도움을 주셔서 감사합니다. – Filip