UITableView 編輯模式左邊圖標的替換

在自定義的cell類中,添加swift

swift:ide

override func setSelected(selected: Bool, animated: Bool) {code

        super.setSelected(selected, animated: animated)it

 

        if self.editing {io

            for (var control) in self.subviews {ast

                if control.isMemberOfClass(NSClassFromString("UITableViewCellEditControl")) {select

                    control = control as! UIControlcompass

 

                    if selected {im

 

                        (control.subviews.last as! UIImageView).image = UIImage(named: "compass")ember

 

                    } else {

                        control.layer.backgroundColor = self.backgroundColor?.CGColor

                    }

                }

            }

        }

        

    }

 

oc:

 

- ( void )setSelected:( BOOL )selected animated:( BOOL )animated

{

     [ super setSelected:selected animated:animated];

 

     if (![ self .viewcontroller isEditing]) {

         

         self .selectionStyle = UITableViewCellSelectionStyleNone;

     

     } else {

         

         self .selectionStyle = UITableViewCellSelectionStyleBlue;

         

         //Bug fix: 第一次點擊cell的左側的複選框沒法選中

         //手動增長edit control的處理

         for (UIControl *control in self .subviews){

             

             if ([control isMemberOfClass: NSClassFromString (@ "UITableViewCellEditControl" )]){

                 [control setSelected:selected];

                 

                 if (selected) {

                     [control setBackgroundColor:[UIColor colorWithRed:0.91f green:0.94f blue:0.98f alpha:1.00f]];

                 } else {

                     [control setBackgroundColor: self .backgroundColor];

                 }

             }

         }

     }

}

相關文章
相關標籤/搜索