IT

UITableViewCell이하고있는 것처럼 보이게 무엇을해야합니까?

lottoking 2020. 9. 15. 08:01
반응형

UITableViewCell이하고있는 것처럼 보이게 무엇을해야합니까?


나는 UITableview 에 대해 알고 있습니다 : 일부 행에 대해 선택을 선택하는 방법다른 행에 대한 선택을 결합하는 방법cell.selectionStyle = UITableViewCellSelectionStyleNone,하지만 UIView같이 셀 (또는 해당 문제에 대한 모든 항목 )을 (회색으로 표시)하는 방법 은 무엇입니까?

중단 된 UITableViewCell


셀의 텍스트 필드를 선택하여 회색으로 표시 할 수 있습니다.

스위프트 4.x

cell!.isUserInteractionEnabled = false
cell!.textLabel!.isEnabled = false
cell!.detailTextLabel!.isEnabled = false

@Ajay 샤르마에 덕분 비활성화 UITableViewCell 것처럼 보이게 하는 방법을 알아 냈습니다 .

// Mac's native DigitalColor Meter reads exactly {R:143, G:143, B:143}.
cell.textLabel.alpha = 0.439216f; // (1 - alpha) * 255 = 143
aSwitch.enabled = NO; // or [(UISwitch *)cell.accessoryView setEnabled:NO];

그런 다음 실제로 셀을 선택하십시오 :

cell.userInteractionEnabled = NO;

내가 사용하고있는 맥락에서 잘 작동하는 Swift 확장. 귀하의 마일리지가 다를 수 있습니다.

스위프트 2.x

extension UITableViewCell {
    func enable(on: Bool) {
        for view in contentView.subviews as! [UIView] {
            view.userInteractionEnabled = on
            view.alpha = on ? 1 : 0.5
        }
    }
}

스위프트 3 :

extension UITableViewCell {
    func enable(on: Bool) {
        for view in contentView.subviews {
            view.isUserInteractionEnabled = on
            view.alpha = on ? 1 : 0.5
        }
    }
}

이제는 myCell.enable(truthValue).


작은 트릭을 사용합니다.

세포의 알파를 설정하십시오. 자신의 요구 사항으로 조건을 설정하고 알파를 설정하십시오.

cell.alpha=0.2;

작동하지 원하는 방식으로 두 번째 트릭을 사용하고

투명한 배경이있는 회색 배경의 셀 크기 이미지를 가져 오는 해당 이미지를 셀 내용 위에 추가하기 만하면됩니다. 이렇게 :

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...


    if(indexPath.row==0)
    {
        cell.userInteractionEnabled=FALSE;

        UIImageView *img=[[UIImageView alloc]init];
        img.frame=CGRectMake(0, 0, 320, 70);
        img.image=[UIImage imageNamed:@"DisableImage.png"];
        img.backgroundColor=[UIColor clearColor];
        [cell.contentView addSubview:img];
        [img release];

    }
    else {
        //Your usual code for cell interaction.

    }
    return cell;
}

확실히 당신의 요구 사항을 확실히하고 있습니다. 이 사용자의 마음에 셀이 Disable이라는 착각을 줄 것입니다. 이 솔루션을 사용하여 문제가 해결되기를 바랍니다.


Kevin Owens의 훌륭한 확장입니다. 이것은 Swift 2.x 작업에 대한 수정입니다 .

extension UITableViewCell {
    func enable(on: Bool) {
        self.userInteractionEnabled = on
        for view in contentView.subviews {
            view.userInteractionEnabled = on
            view.alpha = on ? 1 : 0.5
        }
    }
}

스위프트 3 :

extension UITableViewCell {
    func enable(on: Bool) {
        self.isUserInteractionEnabled = on
        for view in contentView.subviews {
            view.isUserInteractionEnabled = on
            view.alpha = on ? 1 : 0.5
        }
    }
}

UITableViewCell 활성화 / 활성화하기 위해 다음 확장을 만들었거나 사용하는 것이 매우 편리합니다. "UITableViewCell + Ext.h"로 UITableViewCell 확장을 생성합니다.

@interface UITableViewCell (Ext)

- (void)enableCell:(BOOL)enabled withText:(BOOL)text;
- (void)enableCell:(BOOL)enabled withText:(BOOL)text withDisclosureIndicator:(BOOL)disclosureIndicator;
- (void)disclosureIndicator:(BOOL)disclosureIndicator;

@end

"UITableViewCell + Ext.m"에는 다음이 포함됩니다.

@implementation UITableViewCell (Ext)

- (UITableView *)uiTableView {
    if ([[UIDevice currentDevice] systemVersionIsGreaterThanOrEqualTo:@"7.0"]) {
        return (UITableView *)self.superview.superview;
    }
    else {
        return (UITableView *)self.superview;
    }
}

- (void)enableCell:(BOOL)enabled withText:(BOOL)text {
    if (enabled) {
        self.userInteractionEnabled = YES;

        if (text) {
            self.textLabel.alpha = 1.0f;
            self.alpha = 1.0f;
            self.detailTextLabel.hidden = NO;
        }
    }
    else {
        self.userInteractionEnabled = NO;

        if (text) {
            self.textLabel.alpha = 0.5f;
            self.alpha = 0.5f;
            self.detailTextLabel.hidden = YES;
        }
    }
}

- (void)enableCell:(BOOL)enabled withText:(BOOL)text withDisclosureIndicator:(BOOL)disclosureIndicator {
    if (enabled) {
        self.userInteractionEnabled = YES;

        if (text) {
            self.textLabel.alpha = 1.0f;
            self.alpha = 1.0f;
            self.detailTextLabel.hidden = NO;
        }

        self.accessoryType = disclosureIndicator ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
    }
    else {
        self.userInteractionEnabled = NO;

        if (text) {
            self.textLabel.alpha = 0.5f;
            self.alpha = 0.5f;
            self.detailTextLabel.hidden = YES;
        }

        self.accessoryType = UITableViewCellAccessoryNone;
    }
}

- (void)disclosureIndicator:(BOOL)disclosureIndicator {
    if (disclosureIndicator) {
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    else {
        self.accessoryType = UITableViewCellAccessoryNone;
    }
}

@end

셀 방법 :

[cell enableCell:NO withText:NO];

[cell enableCell:NO withText:YES withDisclosureIndicator:YES];

셀 활성화 방법 :

[cell enableCell:YES withText:NO];

[cell enableCell:YES withText:YES withDisclosureIndicator:YES];

도움이 되셨기를 바랍니다.


스위프트 4.X

Kevin Owens의 Nice Extension, 세포의 동작을 수정하고 있습니다.

extension UITableViewCell {
    func enable(on: Bool) {
        self.isUserInteractionEnabled = on
        for view in contentView.subviews {
            self.isUserInteractionEnabled = on
            view.alpha = on ? 1 : 0.5
        }
    }
}

관리자 부르는 방법 :-

cell.enable(on: switch.isOn)


신속하게

cell.isUserInteractionEnabled = false

참고 URL : https://stackoverflow.com/questions/5905608/how-do-i-make-a-uitableviewcell-appear-disabled

반응형