선택 색상을 위해 UITableViewCell
-
05-07-2019 - |
문제
가 있는 경우 사용자 지정 UITableViewCell
사용하지 않는 textLabel
에 설치된 휴지만,대신은 그것의 자신의 그림을,어떻게 변경할 수 있습니 모양의 contentView
에서 선택,그것은 자동으로 기본 텍스트(사용자 정의 설정하여 selectedTextColor:
)?
변경하는 경우 tableView:willSelectRowAtIndexPath:
, 에,그것만 업데이트한 후에 파란색 선택 배경입니다,하지만 하는 동안 그것은 애니메이션,같은 제가 원하는 것입니다.
해결책
지 서브 클래스 UITableViewCell 와 기본 동작을 사용합니다.당신은 완전히 사용자 정의할 수 있습니다 셀없이 모든 하위 클래스.
읽기 이 문서 자세한 내용은.
다른 팁
이 코드를 추가하 tableview cellForRowAtIndexPath 방법 및 변경 색상을 위해 UITableViewCell 선택 스타일입니다.
//-------------------------------------------------------------------------
//background selected view
UIView *viwSelectedBackgroundView=[[UIView alloc]init];
viwSelectedBackgroundView.backgroundColor=[UIColor colorWithRed:124.0/255.0 green:202.0/255.0 blue:227.0/255.0 alpha:1.0];
cell.selectedBackgroundView=viwSelectedBackgroundView;
//-------------------------------------------------------------------------
이 있으면 하위 UITableViewCell,다음 설정할 수 있습의 요소가 세포를 재정의하여 다음과 같다:
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
if(highlighted) {
self.backgroundColor = [UIColor redColor];
} else {
self.backgroundColor = [UIColor clearColor];
}
[super setHighlighted:highlighted animated:animated];
}
제휴하지 않습니다 StackOverflow