Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of text in a tableview swift?

I've created a tableview in swift and I'm customising appearance to make it look nicer. I'd like to change the appearance to have a clear background and white text color. Tableview function:

  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell:UITableViewCell = self.myTableView
        .dequeueReusableCellWithIdentifier("cell")! as UITableViewCell
    let score = scores[indexPath.row]
    cell.textLabel!.text = String(score.gameScore!)
    UITableViewCell.appearance().textLabel?.textColor = UIColor.whiteColor();
    UITableViewCell.appearance().backgroundColor = UIColor.clearColor();

    return cell;
}

So the second part works with the clear cells but but the first part doesn't for some reason. I checked out some sources online but can't seem to get this one right:

How to change text color in tableView section in swift

https://www.natashatherobot.com/ios-change-uitableviewcell-selection-color-app-wide/

Any help would be greatly appreciated! Thanks

like image 347
ThirtyKnots Avatar asked Dec 06 '22 17:12

ThirtyKnots


1 Answers

You need to change the color of text using the "cell" object you created. So it should be like this

cell.textLabel?.textColor = UIColor.cyanColor()

Change it to any color of your desire

like image 183
Umair Afzal Avatar answered Jan 20 '23 13:01

Umair Afzal