Swift viewForHeaderInSection不使用自定义颜色

时间:2015-04-24 07:06:57

标签: uitableview swift uicolor

我遇到了tableView的viewForHeaderInSection方法的非常奇怪的行为:

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 30.0
}

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    let label = UILabel(frame: CGRectMake(10.0, 10.0, tableView.frame.size.width, 30.0)) // Doesn't care about x, y offset
    label.text = "Results"
    label.textColor = UIColor.blueColor()
    label.backgroundColor = UIColor.orangeColor() // Not Working: UIColor(red: 88, green: 130, blue: 202, alpha: 1.0)

    return label
}
  1. 无论我在CGRectMake构造函数中选择哪个值,我的标签都会始终贴在左上角。
  2. textColorbackgroundColor属性使用标准的UIColor颜色,例如UIColor.blueColor(),但未能使用UIColor(red: 88, green: 130, blue: 202, alpha: 1.0) - >等颜色没有显示任何内容
  3. 你们可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

使用此:

    let newRed = CGFloat(88)/255
    let newGreen = CGFloat(130)/255
    let newBlue = CGFloat(202)/255

    self.init(red: newRed, green: newGreen, blue: newBlue, alpha: 1.0)