Open churabou opened 6 years ago
class View: UIView {
override var frame: CGRect {
didSet {
print("didSet \(frame)")
}
}
}
let v = View()
v.bounds = view.bounds
v.backgroundColor = .red
view.addSubview(v)
UIView.animate(withDuration: 0.3) {
v.bounds.size = CGSize(width: 300, height: 300)
}
class View: UIView {
override var frame: CGRect {
didSet {
print("didSet \(frame)")
}
}
}
let v = View()
print("instantiate \(v.frame)")
v.bounds = view.bounds
print("v.bounds = view.bounds \(v.frame)")
v.center = view.center
print("v.center = view.center \(v.frame)")
v.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
print("v.frame = CGRect(x: 100, y: 100, width: 100, height: 100) \(v.frame)")
v.bounds.size = CGSize(width: 200, height: 200)
print("v.bounds.size = CGSize(width: 200, height: 200) \(v.frame)")
v.transform = v.transform.scaledBy(x: 2, y: 1).translatedBy(x: -40, y: 50)
print("v.transform = v.transform.scaledBy(x: 2, y: 1).translatedBy(x: -40, y: 50) \(v.frame)")
didSet (0.0, 0.0, 0.0, 0.0)
instantiate (0.0, 0.0, 0.0, 0.0)
v.bounds = view.bounds (-187.5, -333.5, 375.0, 667.0)
v.center = view.center (0.0, 0.0, 375.0, 667.0)
didSet (100.0, 100.0, 100.0, 100.0)
v.frame = CGRect(x: 100, y: 100, width: 100, height: 100) (100.0, 100.0, 100.0, 100.0)
v.bounds.size = CGSize(width: 200, height: 200) (50.0, 50.0, 200.0, 200.0)
v.transform = v.transform.scaledBy(x: 2, y: 1).translatedBy(x: -40, y: 50) (-130.0, 100.0, 400.0, 200.0)
storeされているframeの値と getしてくるframeの値が違う
class A {
var test: Int {
get {
return self.test * 2
}
set {
self.test = newValue
}
}
}
class B: A {
override var test: Int {
didSet {
print(test)
}
}
}
get - set もういっかい読もう
backgroundColorとか意味ない。
意外と手こずった
等間隔に表示するには便利だし積極的に使っていいと感じた。
https://gist.github.com/KentarouKanno/29285df0bdf5b8b21078
https://qiita.com/yucovin/items/ff58fcbd60ca81de77cb
うまくいかなかった例
UIImage().withRenderingMode(.alwaysTemplate)は透明度飲み色情報抜き でtintcolorで色を変えられる