일정관리 앱에서 흔히 볼 수 있는, 완료 항목에 줄을 긋는 방법

  cell.planTitleLabel.text = plans![indexPath.row].title
          if plans![indexPath.row].check == true {
              cell.planCheckImage.image = UIImage(named: "ico_checkOn")
              cell.planTitleLabel.textColor = UIColor(hex: checkOnTextColor)
              let attributedString = NSMutableAttributedString(string: plans![indexPath.row].title)
              attributedString.addAttribute(NSAttributedStringKey.strikethroughStyle, value: 1, range: NSMakeRange(0, attributedString.length))
              attributedString.addAttribute(NSAttributedStringKey.strikethroughColor, value: UIColor(hex: checkOnTextColor), range: NSMakeRange(0, attributedString.length))
              cell.planTitleLabel.attributedText = attributedString
          } else {
              cell.planCheckImage.image = UIImage(named: "ico_checkOff")
              cell.planTitleLabel.textColor = UIColor(hex: checkOffTextColor)
              let attributedString = NSMutableAttributedString(string: plans![indexPath.row].title)
              attributedString.removeAttribute(NSAttributedStringKey.strikethroughStyle, range: NSMakeRange(0, attributedString.length))
              cell.planTitleLabel.attributedText = attributedString
          }

적용 예:



+ Recent posts