分组 UITableView 中的中心页脚 UILabel - Swift [英] Center footer UILabel in grouped UITableView - Swift

查看:32
本文介绍了分组 UITableView 中的中心页脚 UILabel - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在向我的应用程序添加一个信息页面,并希望在分组的 UITableView 的页脚中显示应用程序的版本号.我有它显示,但我不知道如何将它居中.

I'm currently adding an information page to my app, and wish to display the version number of the app centred in the footer of a grouped UITableView. I have it displaying, but I'm not sure how to go about centring it.

我看过使用 tableviews viewForFooterInSection;这是正确的前进方式,还是有更简单的方法?

I've looked at using the tableviews viewForFooterInSection; would this be the correct way going forward, or is there a simpler way?

非常感谢.

推荐答案

只需在你的tableView中添加一个footer,不管你有多少个section,它都会放在底部>

let tableViewFooter = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 50))
            tableViewFooter.backgroundColor = UIColor.greenColor()        
let version = UILabel(frame: CGRectMake(8, 15, tableView.frame.width, 30))
version.font = version.font.fontWithSize(14)
version.text = "Version 1.x"
version.textColor = UIColor.lightGrayColor()
version.textAlignment = .Center;

tableViewFooter.addSubview(version)

tableView.tableFooterView  = tableViewFooter

如果您想为每个部分添加页脚

在您的 tableView(tableView: UITableView, viewForHeaderInSection section: Int) 中创建一个 UIView() ->UIView?方法并向该视图添加标签并将标签居中.

Create a UIView() in your tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? method and add a label to that view and center the label within it.

示例:

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let view = UIView()

        let version = UILabel(frame: CGRectMake(8, 15, tableView.frame.width, 30))
        version.font = version.font.fontWithSize(14)
        version.text = "Version 1.x"
        version.textColor = UIColor.lightGrayColor()
        version.textAlignment = .Center;

        view.addSubview(version)

        return view
    }

这篇关于分组 UITableView 中的中心页脚 UILabel - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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