2016-07-23 109 views
0

好了,香港專業教育學院創建的UITextField程序在這裏 -如何防止uitextfield擴展它的寬度,但允許其文本的高度?

ideaTextField.frame = CGRectMake(0, 0, screenSize.width * (0.72), screenSize.height * (120/568)) //limit on characters 
     ideaTextField.text = "Give us an idea" 
     ideaTextField.center = CGPointMake(screenSize.width * 0.5, screenSize.height * 1.1) 
     ideaTextField.font = UIFont(name: "Roboto", size: screenSize.height * (16/568)) 
     ideaTextField.textAlignment = .Center 
     ideaTextField.textColor = colorWithHexString(chosenColor) 

     ideaTextField.delegate = self 
     ideaTextField.addTarget(self, action: "startedEntering2:", forControlEvents: UIControlEvents.TouchDown) 
     view.addSubview(ideaTextField) 

,正如你可以看到我已經明確設置寬度/幀,並試圖但就像一個標籤着集線至0 /無窮大的數量。我的問題是,當我開始輸入文字越過場的寬度領域只是不斷橫向擴展:

enter image description here

進出口設置的字數限制,但如果有的話,我需要的領域只在垂直方向擴大。我怎樣才能做到這一點?

+5

'UITextField'用於單行文本。你需要爲多行使用'UITextView'。 'UITextView'會自動下拉到下一行。 – tktsubota

+0

** 1。**使用textview,禁用滾動** 2。**添加約束Leading,Trailing,Top和Bottom。 ** 3。**將底部佈局關係從**等**改爲**大於或等於** – Gokul

回答

相關問題