0
我對UIView和UIView子類有個問題。 在我的故事板中,我添加了一個UIView(寬度:368高度:552,水平和垂直居中)。 我已連接這個UIView的到我的ViewController:Swift:兩個UIViews的大小不同
@IBOutlet weak var mapViewOutlet: UIView!
的我要創造我自己的UIView的子類的對象:
var bounds:CGRect = CGRectMake(0, 0, mapViewOutlet.frame.size.width, mapViewOutlet.frame.size.height)
self.roomView = RoomView(frame: bounds, image: testMap)
init方法的第一個參數是界限。在那裏,我將mapViewOutlet的大小賦予子類。圖像參數是綠色圖像(您可以在附加圖像中看到此圖像)。 但現在綠色圖像的大小不適合灰色mapViewOutlet的大小。
let testFrame : CGRect = CGRectMake(0,0,frame.size.width ,frame.size.height)
var testView : UIView = UIView(frame: testFrame)
testView.backgroundColor = UIColor(red: 0.5, green: 4, blue: 0.5, alpha: 1.0)
testView.alpha=0.5
self.addSubview(testView)
有誰知道他們怎麼不適合:
綠色的UIView如下產生?
謝謝。