2017-05-05 124 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) 
相关问题