2016-09-15 32 views
0

我發現在我的應用中放置一個視圖並根據我的需要調整大小與HTML中的div非常相似。我應該以這種方式使用它們嗎?iOS「視圖」和HTML div是否相似?

下面是我想要使用視圖的地方的示例。

enter image description here

我要填寫在,我應該在這裏使用一個看法?或更多的語義?以期

最終結果:

enter image description here

+0

您是否想用藍色填充整個頂部?導航欄應該自動填充... –

+0

@RashwanL我想設置狀態欄在這種情況下有藍色背景。但是一般來說,如果我想在某個地方放置一個矩形,那麼視圖會是一個不錯的選擇? –

回答

1

如果你想設置的地方一個矩形如果you're使用您的故事板,你肯定可以使用一個UIView(),一定要設置正確的約束,如果you're做編程,你可以做到以下幾點得到它與所有手機大小的工作:

雨燕3.0:

let screen = UIScreen.main.bounds 

let anotherView = UIView(frame: CGRect(x: 0, y: 0, width: screen.width, height: 45)) 
anotherView.backgroundColor = UIColor.blue 
view.addSubview(anotherView) 

Swift 2.x:

let screen = UIScreen.mainScreen().bounds 

let anotherView = UIView(frame: CGRect(x: 0, y: 0, width: screen.width, height: 45)) 
anotherView.backgroundColor = UIColor.blueColor() 
view.addSubview(anotherView) 
+1

非常感謝! –