hel*_*ikh 1 uibutton ios swift
我想更改表视图页脚中的按钮文本颜色.这是我正在使用的代码,但它不起作用
override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))
footerView.backgroundColor = UIColor.blackColor()
let rgbValue = 0x4097d4
let color = Util.getColor(rgbValue)
let button = UIButton(type: UIButtonType.System) as UIButton
button.frame = CGRectMake(0, 0, 414, 65)
button.setTitle("my Button", forState: UIControlState.Normal)
button.titleLabel?.textColor = UIColor.whiteColor()
button.titleLabel?.font = UIFont(name: "Montserrat-Regular", size: 20.0)
button.backgroundColor = UIColor( red: CGFloat(color[0]), green: CGFloat(color[1]), blue:CGFloat(color[2]), alpha: 1.0 )
footerView.addSubview(button)
return footerView
}
override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 40.0
}
Run Code Online (Sandbox Code Playgroud)
一个问题是文本颜色没有改变,另一个问题是我的tableview中有很多静态行.我正在修复底部的按钮,但问题是当屏幕到达结束时,如果我点击屏幕并拖动屏幕上方仍显示按钮后面的一些空格
不要直接设置标签的颜色; 用-setTitleColor:forState:.
button.setTitleColor(UIColor.whiteColor(), forState:UIControlState.Normal)
Run Code Online (Sandbox Code Playgroud)