在 UITableView 的 Section Header 中添加填充 [英] Add padding to Section Header in UITableView

查看:24
本文介绍了在 UITableView 的 Section Header 中添加填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了这个部分的标题标题,不幸的是我不知道如何在右侧添加一些填充.

I created this section header title and unfortunately I don't know how to add some padding on the right.

这是我的代码:

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let title: UILabel = UILabel()
    title.text = "Days"
    title.backgroundColor = UIColor.lightGrayColor()
    title.textAlignment = NSTextAlignment.Right
    return title
}

推荐答案

你可以这样做:

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let view = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
    let label = UILabel(frame: CGRect(x: 15, y: 5, width: tableView.frame.width, height: 20))
    label.text = "Days"
    label.textAlignment = .right
    view.addSubview(label)
    return view
}

这篇关于在 UITableView 的 Section Header 中添加填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆