DAY 29
0

## wow，第29天了欸。30天其實說快不快，說慢不慢。默默的也就發了30篇文了

### 實作Frame及Bound

``````let blueView: UIView = UIView()

setBlueView()
}

func setBlueView() {
blueView.backgroundColor = #colorLiteral(red: 0.1764705926, green: 0.4980392158, blue: 0.7568627596, alpha: 1)
blueView.frame = CGRect(x: 0, y: 100, width: 200, height: 200)
print("blueView frame:\(blueView.frame), blueView Bound:\(blueView.bounds)")
}
``````

• blueView Frame:(0.0, 100.0, 200.0, 200.0)
• blueView Bound:(0.0, 0.0, 200.0, 200.0)

``````func newPlaceBlueView() {
blueView.frame = CGRect(x: +10, y: +100, width: 200, height: 200)
print("blueView frame:\(blueView.frame), blueView Bound:\(blueView.bounds)")
blueView.bounds = CGRect(x: +10, y: +100, width: 200, height: 200)
print("blueView frame:\(blueView.frame), blueView Bound:\(blueView.bounds)")
}
``````

• 改變frame之後
blueView Frame:(10.0, 100.0, 200.0, 200.0)
blueView Bound:(0.0, 0.0, 200.0, 200.0)

bound沒有改變，主要是y軸計算方式也是從superview開始+100，所以frame的x,y會是(10.0, 100.0)。視圖位置也會改變。

• 改變bound之後
blueView Frame:(10.0, 100.0, 200.0, 200.0)
blueView Bound:(10.0, 100.0, 200.0, 200.0)

Swift!從新手到微上手30