Thi*_*guy 1 header constraints alignment uitableview ios
标签标题对齐是左边的,但我希望居中.我的约束是什么问题?
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
{
var title: UILabel = UILabel()
title.text = sectionsArray[section]
title.textColor = UIColor(red: 77.0/255.0, green: 98.0/255.0, blue: 130.0/255.0, alpha: 1.0)
title.backgroundColor = UIColor(red: 225.0/255.0, green: 243.0/255.0, blue: 251.0/255.0, alpha: 1.0)
title.font = UIFont.boldSystemFontOfSize(10)
var constraint = NSLayoutConstraint.constraintsWithVisualFormat("H:[label]", options: NSLayoutFormatOptions.AlignAllCenterX, metrics: nil, views: ["label": title])
title.addConstraints(constraint)
return title
}
Run Code Online (Sandbox Code Playgroud)
我想你可能需要设置UILabel的textAlignment属性.即使它居中,我认为文本默认为左对齐.
title.textAlignment = NSTextAlignment.Center
Run Code Online (Sandbox Code Playgroud)
在Swift 4中心已经重命名为小写.
title.textAlignment = NSTextAlignment.center
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3929 次 |
最近记录: |