2016-02-22 105 views
-1

我在一個基本的應用程序工作,出於某種原因,我不能以CGPointMake爲中心視圖(文本框)。我知道textBox.center = self.view.center;將中心視圖,但我不知道爲什麼CGPointMake不工作。我正在使用Swift。CGPoint不正確定位UIView

textBox.font = UIFont.systemFontOfSize(15) 
    textBox.keyboardType = UIKeyboardType.Default 
    textBox.textAlignment = NSTextAlignment.Center 
    CGPointMake(187.5, 333.5) 
    textBox.returnKeyType = UIReturnKeyType.Done 
    self.view.addSubview(textBox) 
+2

'CGPointMake(187.5,333.5)'未分配給textBox的任何屬性。你確定 ? –

回答

-1

你可以通過這個代碼

CGPointMake(187.5, 333.5) 提出的觀點,但你沒有文本框的中心分配到了這一點。 因此,使用此代碼

textBox.center = CGPointMake(187.5, 333.5);