-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIterCell.swift
68 lines (50 loc) · 1.79 KB
/
IterCell.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// IterCell.swift
// Dday
//
// Created by 한수진 on 2021/08/09.
//
import UIKit
class IterCell: UITableViewCell {
@IBOutlet var iterButtons: [UIButton]!
var indexOfOneAndOnly: Int?
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// week.setBackgroundColor(.red, for: .normal)
// week.setBackgroundColor(.blue, for: .selected)
// week.setBackgroundColor(.gray, for: .disabled)
}
@IBAction func touchButton(_ sender: UIButton){
print("btn touch")
if indexOfOneAndOnly != nil{
if !sender.isSelected{
for index in iterButtons.indices{
iterButtons[index].isSelected = false
}
sender.isSelected = true
indexOfOneAndOnly = iterButtons.firstIndex(of: sender)
}else{
sender.isSelected = false
indexOfOneAndOnly = nil
}
}else{
sender.isSelected = true
indexOfOneAndOnly = iterButtons.firstIndex(of: sender)
}
}
}
extension UIButton {
func setBackgroundColor(_ color: UIColor, for state: UIControl.State) {
UIGraphicsBeginImageContext(CGSize(width: 1.0, height: 1.0))
guard let context = UIGraphicsGetCurrentContext() else { return }
context.setFillColor(color.cgColor)
context.fill(CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0))
let backgroundImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.setBackgroundImage(backgroundImage, for: state)
}
}