它适用于宽度为320的手机,如iPhone 4和5.当我在模拟器上测试6及以上时,uitableview部分标题由于某种原因不再可见。以下是相关代码:
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 3
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView(frame: CGRectMake(0, 0, self.tableView.frame.size.width, 30))
headerView.backgroundColor = UIColor(red:0.20, green:0.47, blue:0.45, alpha:1.00)
let sectionLabel = UILabel(frame: CGRectMake(0, 0, self.tableView.frame.size.width, 30))
switch section {
case 0:
sectionLabel.text = "Monday to Friday"
case 1:
sectionLabel.text = "Saturday"
case 2:
sectionLabel.text = "Sunday"
default:
sectionLabel.text = ""
}
sectionLabel.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)
sectionLabel.textColor = UIColor.whiteColor()
sectionLabel.textAlignment = NSTextAlignment.Center;
headerView.addSubview(sectionLabel)
return headerView
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> Float {
return 30.0
}