uitableview 강조 표시를 비활성화하지만 개별 셀 선택 허용
셀을 탭하면 행이 선택되고 강조 표시됩니다. 이제 내가하고 싶은 것은 강조 표시를 비활성화하지만 선택을 허용하는 것입니다. 그 주위에 방법이 있습니까?이 질문에 대답하지만 선택과 강조 표시를 모두 비활성화합니다.
Storyboard에서 셀의 선택 스타일을 "없음"으로 설정할 수 있습니다.
또는 코드에서 :
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Swift 3 :
cell.selectionStyle = UITableViewCellSelectionStyle.none
Swift 4 이상 :
cell.selectionStyle = .none
UITableViewCell
의 selectedBackgroundView
색상을 투명으로 변경합니다 .
let clearView = UIView()
clearView.backgroundColor = UIColor.clearColor() // Whatever color you like
UITableViewCell.appearance().selectedBackgroundView = clearView
또는 특정 셀에 대해 설정하려면 :
cell.backgroundView = clearView
셀 선택 스타일을 없음으로 설정하십시오-
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
이것은 당신의 문제를 해결할 것입니다
대한 스위프트 3.0 :
cell.selectionStyle = .none
Swift의 경우 :
UITableViewCell.selectionStyle = UITableViewCellSelectionStyle.None;
또는 신속하게 셀을 서브 클래 싱 할 때 :
class CustomCell : UITableViewCell {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
selectionStyle = .None
}
}
신속한 3
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
Swift 3에서 프로그래밍 방식을 찾는 사람들을 위해
cell.selectionStyle = UITableViewCellSelectionStyle.none
스토리 보드에서 셀 자체의 선택 속성을 설정할 수 있습니다.
Objc의 경우 :
[셀 setSelectionStyle : UITableViewCellSelectionStyleNone];
- (void)viewDidLoad {
[super viewDidLoad];
_tableView.allowsSelection = YES;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
.. .. .. ..
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
. . . . ..
}
사용자 정의 색상을 추가하려면 아래 코드를 사용하십시오. 그리고 그것을 투명하게 사용하기 위해alpha: 0.0
cell.selectedBackgroundView = UIView(frame: CGRect.zero)
cell.selectedBackgroundView?.backgroundColor = UIColor(red:0.27, green:0.71, blue:0.73, alpha:1.0)
사용자 정의 색상을 사용하고 모서리를 둥글게 보이게하려면 다음을 사용하십시오.
cell.layer.cornerRadius = 8
또한 더 나은 애니메이션과 느낌을 위해 이것을 사용하십시오.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
들어 스위프트 (5) 가장 좋은 방법은 다음과 같습니다
cell.selectionStyle = .none
빠른 3 솔루션은 편집 모드에서도 작동합니다.
cell.selectionStyle = .gray
cell.selectedBackgroundView = {
let colorView = UIView()
colorView.backgroundColor = UIColor.black.withAlphaComponent(0.0)
//change the alpha value or color to match with you UI/UX
return colorView
}()
'your programing' 카테고리의 다른 글
클래스, 객체 및 인스턴스의 차이점 (0) | 2020.10.13 |
---|---|
버튼을 여러 번 빠르게 클릭하지 마십시오. (0) | 2020.10.13 |
mysql.sock을 찾을 수 없습니다 (0) | 2020.10.13 |
요소의 올바른 오프셋을 얻는 방법? (0) | 2020.10.13 |
Android PopupWindow가 활성화되었을 때 배경이 흐리거나 어둡습니다. (0) | 2020.10.13 |