3

I want to change the button text color which is in my Table view Footer. Here is code which i am using but it isn't working

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
}

one problem is that text color doesn't change and another problem is I have a lot of static rows in my tableview. I am fixing the button at the bottom but the problem is when screen reaches at the end, If I click on the screen and drag screen above it still shows some white space after the button

hellosheikh
  • 2,929
  • 8
  • 49
  • 115

1 Answers1

14

Don’t set the label’s color directly; use -setTitleColor:forState:.

button.setTitleColor(UIColor.whiteColor(), forState:UIControlState.Normal)
Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131
  • thank you very much.. it works – hellosheikh Dec 16 '15 at 19:38
  • could you answer my another problem. if possible can you give me small hint regarding my next problem – hellosheikh Dec 16 '15 at 19:39
  • For the other problem, it depends on what behavior you want. If you don’t want the footer to scroll with the table view at all, then refer to [this question](http://stackoverflow.com/questions/15687370/). If you do want it to scroll, but want the button’s color to extend past the bottom of the button, then you should create an additional solid-color view beneath the button to fill that space. – Noah Witherspoon Dec 16 '15 at 20:24
  • thanks for your answer. well I fixed the problem. actually It was the bounce property which I should unchecked it which now I did – hellosheikh Dec 16 '15 at 20:29
  • Thanks a lot... saved the day... I was trying button.titleLabel?.textColor = .red previously and it didn't work when the awake from nib on a cell... but your method worked just as expected.. – Rakshitha Muranga Rodrigo May 27 '20 at 11:22