ProgramingTip

UITableView에서 확인 표시의 색상 변경

bestdevel 2021. 1. 8. 23:06
반응형

UITableView에서 확인 표시의 색상 변경


누군가가 UITableView의 체크 표시에서 색상을 변경하는 방법을 보여줄 수 있습니까?

검색했지만 작동하지 않는 것입니다.

건배


Apple은 체크 표시의 색상을 변경하는 공개 방법을 제공하지 않고 이미지로 변경해야합니다.

이것은 매우 간단합니다. 셀의 accesoryView 속성을 올바른 색상의 확인 표시가 포함 된 UIImageView로 설정하기 만하면됩니다.

다음과 같이 표시됩니다.

UIImageView *checkmark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"coloredCheckmark.png"]];
cell.accessoryView = checkmark;
[checkmark release];

즐겨!


iOS SDK가 변경된 답변 이후 iOS SDK가 변경 접수 새로운 답변으로 업데이트 할 생각했습니다.

실제로 속성을 UITableViewCell조정하여 확인 표시의 색상을 설명 할 수 있습니다 tintColor.UITableViewCell.

달리 지정하지 않는 한 모든 인스턴스가 특수한 색상을 갖도록 모든 UITableViewCell에 대한 모양 프록시를 수도 있습니다.

[[UITableViewCell appearance] setTintColor:[UIColor redColor]];

Swift 버전을 찾고있는 권한 :

세포에 직접

예를 들어 tableView(_:,cellForRowAtIndexPath:)

cell.tintColor = UIColor.redColor()

외관 프로토콜 사용

UITableViewCell.appearance().tintColor = UIColor.redColor()

다음은 iOS 7에서 저에게 저에게.

[self.tableView setTintColor:[UIColor someColor]];

이 이미지는 스토리 보드 에서이 작업을 수행하는 방법을 보여줍니다. 편의 색상은 체크 표시 색상입니다.

여기에 이미지 설명 입력


igraczech의 대답은 대부분이하지만 iOS 6 이상에서는 전체 테이블이 뷰의 기본 색상 만 수 있습니다.

[self.tableView setTintColor:[UIColor someColor]];

이것은 나를 위해 일 항목 체크 표시에 색칠 할 수 있습니다.


iOS 7을 시작하면 뷰 컨트롤러 뷰의 색상을 설정 하여이 색상이 모든 하위 뷰에 표시 할 수 있습니다. 따라서 UITableViewCell의 체크 표시를 보라색 (예 :)으로 설정 광고주가 viewWillAppear 메소드에서 다음을 수행해야합니다.

[self.view setTintColor:[UIColor purpleColor]];

 UITableViewCell *cell=(UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier" forIndexPath:indexPath];
cell.tintColor=UIColor.whiteColor;
return cell;

UIAccessoryTypeCheckmark (오른쪽)는 테이블 뷰의 배경색을 상속합니다.

self.tableView.backgroundColor = [UIColor clearColor];

#import "UIImage+Color.h"

UIImage *image = [[UIImage imageNamed:@"ic_check_black_24dp.png"] changeColor:CLR_BUY];
UIImageView *checkmark = [[UIImageView alloc] initWithImage:image];
cell.accessoryView = checkmark;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
HNCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HNCustomTableViewCell" forIndexPath:indexPath];
cell.tintColor = [UIColor colorWithRed:0.99 green:0.74 blue:0.10 alpha:1.0];
return cell;
}

그것은 나를 위해 일합니다.


나는 항상 다음과 같은 쉬운 방법을 사용했습니다.

UITableViewCell *cell = ...;
cell.tintColor = [UIColor greenColor];
cell.accessoryType = UITableViewCellAccessoryCheckmark;

자신의 이미지를 사용할 수 없습니다. 다음 코드를 사용하여로드 한 뷰에서 간단히 설명 수 있습니다.

[self.tableView setTintColor:[UIColor colorWithRed:250/255.0 green:223/255.0 blue:6/255.0 alpha:1]]

건배!


위의 답변은 모두 훌륭합니다. 하지만 전 세계적으로보고 그냥

UITableViewCell.appearance().tintColor = .green

멋진 작은 트릭 :)


Swift 3.1, iOS 9 이상

if #available(iOS 9.0, *) {
            UIImageView.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).tintColor = UIColor.themeTint //add your color here 
        } else {
            // Fallback on earlier versions
        }

결과

참조 URL : https://stackoverflow.com/questions/7641228/change-color-on-checkmark-in-uitableview

반응형