当我在viewController中默认添加tableView时,tableView会滚动,但我希望它是静态的.可能吗?
这是我的代码:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return names.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableview.dequeueReusableCellWithIdentifier("cell") as! TableViewCell
cell.username.text = names[indexPath.row]
return cell
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int
{
return 1
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return 50.0
}
Run Code Online (Sandbox Code Playgroud)
UITableView当内容大小适合表格视图的大小时, 滚动将被禁用
if (tableView.contentSize.height < tableView.frame.size.height) {
tableView.scrollEnabled = false
}
else {
tableView.scrollEnabled = true
}
Run Code Online (Sandbox Code Playgroud)
如果您想禁用滚动而不管 contentSize:
tableView.scrollEnabled = false
Run Code Online (Sandbox Code Playgroud)
更改UITableView分隔线的颜色(按照评论中的要求):
tableView.separatorColor = UIColor(red:0.16, green:0.17, blue:0.20, alpha:1.00)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5337 次 |
| 最近记录: |