투명한 배경으로 UITableViewCell을 만드는 방법
의 배경색 UITableViewCell
을 투명하게 설정하려고합니다 . 그러나 아무것도 작동하지 않는 것 같습니다. 내부에 이미지 / 버튼이 있고 tableViewCell
흰색 grouptableview
배경을 사라지게하여 이미지와 버튼에 대한 '부동'효과를 얻고 싶습니다 (마치 내부에없는 것처럼 tableview
).
이것이 어떻게 성취 될 수 있는지 아십니까?
다른 옵션이 모두 작동하지 않으면 이것을 시도하십시오.
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
이것은 실제로 UITableViewCell의 문서에 답변되어 있습니다. 따라서 컨트롤에 투명도를 설정 해야 하지만 실제 셀 배경색 은 아래에 따라 설정 해야합니다 .
"참고 : 셀의 배경색을 변경하려면 (UIView에서 선언 한 backgroundColor 속성을 통해 셀의 배경색을 설정하여) tableView : willDisplayCell : forRowAtIndexPath : 메서드가 아닌 델리게이트의 메서드에서 변경해야합니다. tableView : cellForRowAtIndexPath : 데이터 소스. 그룹 스타일 테이블보기에서 셀의 배경색을 변경하면 iOS 3.0에서 이전 버전의 운영 체제와 다른 효과가 있습니다. 이제 둥근 사각형 내부 영역에 영향을줍니다. 그 밖의 지역의. "
https://developer.apple.com/documentation/uikit/uitableviewcell
다음 문서로 시작하여 배경색을 올바르게 설정하십시오.
http://pessoal.org/blog/2009/02/25/customizing-the-background-border-colors-of-a-uitableview/
그런 다음 다음 줄을 모두 시도하십시오.
[[cell contentView] setBackgroundColor:[UIColor clearColor]];
[[cell backgroundView] setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundColor:[UIColor clearColor]];
UITableViewCell에는 하나 이상의 뷰가 숨겨져 있습니다. 이것은 당신의 방식으로 모든 것을 명확하게 할 것입니다.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView.backgroundColor = [UIColor clearColor];
}
나는 간단한 해결책이있다
Objective-c 버전 :
cell.backgroundColor = [UIColor clearColor];
Swift 버전 :
cell.backgroundColor = UIColor.clearColor()
기본적으로 UITableViewCell의 배경은 흰색입니다. 그렇게하면 myCell.backgroundColor = [UIColor clearColor];
UITableViewCell이 투명 해지지 만 UITableView (UITableViewCell의 contener)도 기본적으로 흰색 배경을 가지고 있기 때문에 차이를 느끼지 못할 것입니다.
UIView 배경을보고 싶다면 셀과 테이블 배경을 투명하게 만들어야합니다.
myTableView.backgroundColor = [UIColor clearColor];
myTableCell.backgroundColor = [UIColor clearColor];
마틴 마가 키안
내 사용자 정의 tableviewcell 배경 이미지가 흰색 레이블 배경으로 오버레이되는 문제가 있었고 모든 것을 시도하고 마침내 viewWillAppear에서 배경을 명확한 색상으로 설정하여 트릭을 수행했습니다.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.tableView.backgroundColor = [UIColor clearColor]; // if this is not here, cell background image is covered with a white rectangle :S
}
그리고 rowForCellAtIndexPath에서 배경 이미지를 설정했습니다.
if(!cell) {
cell = [[[UITableViewCell alloc] initWithFrame: ...
UIImageView *cellBG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellbg.jpg"]];
[cell setBackgroundView:cellBG];
[cellBG release];
}
스토리 보드를 사용하는 경우 프로토 타입 UITableViewCells에 대해 "불투명"을 선택 취소해야합니다.
세 단계가 있습니다.
- cell.contentView.backgroundColor = UIColor.clear
- 드로잉 섹션의 속성 관리자에서 테이블 뷰 셀에 대한 불투명 확인란을 선택 취소합니다. 스토리 보드에서 테이블 뷰 셀 프로토 타입을 클릭하고 속성 검사기를 열어서 찾을 수 있습니다. 아래로 스크롤하면 찾을 수 있습니다.
- 2 단계와 동일한 위치의 드롭 다운에서 배경을 투명 색상으로 선택합니다.
- 앱 실행
Swift 4.1의 솔루션은 다음과 같습니다.
override func viewDidLoad() {
super.viewDidLoad()
tableView.backgroundView = UIImageView(image: "Image")
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell.backgroundColor = UIColor.clear
{
'IT TIP' 카테고리의 다른 글
두 변수의 값을 바꾸는 PHP 함수가 있습니까? (0) | 2020.10.30 |
---|---|
Ruby gem mysql2 설치 실패 (0) | 2020.10.30 |
솔트 생성 및 오픈 소스 소프트웨어 (0) | 2020.10.30 |
ArrayList에서 항목 이동 (0) | 2020.10.30 |
라 라벨은 다 대다 관계 저장 / 업데이트 (0) | 2020.10.30 |