2017-05-05 55 views

回答

1

使用此代碼ViewDidAppear

tableView.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: desiredHeight) 
+1

這不會在Swift 3中編譯。 – Welton122

+0

更新了答案bro。謝謝 ;-) –

-1

這是雨燕3.1的版本:

//Create table view 
let tableView = UITableView(); 
//Set frame 
tableView.frame = CGRect(x: 0, y: 0, width: 100, height:100); 
//Add the table to a view as a subview 
superView.addSubview(tableView); 
//... 
-1

Sivajee Battina回答techanically是正確的,但是,你不應該使用CGRectMake使用斯威夫特時3.這是Swift 3的答案:

tableView.frame = CGRect(x: 0, y: 0, width: myWidth, height: myHeight) 
1

步驟1:的UITableView

的出口

Create IBOutlet of UITableView

@IBOutlet var tableView: UITableView! 

步驟2:()的tableView在viewDidLoad中方法的現在設置框架。

viewDidLoad中()

tableView.backgroundColor = UIColor.black 
tableView.frame = CGRect(x: 0, y: 0, width: 180, height: 400) 
0

試試這個代碼

tableView.frame = CGRect(x: 10, y: 10, width: yourwidth, height: yourheight) 
相關問題