omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Changing text color in Table View Cell

    Pythonista
    4
    5
    4182
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • techteej
      techteej last edited by

      Is there any way to change the text color in Table View Cell?

      1 Reply Last reply Reply Quote 0
      • dgelessus
        dgelessus last edited by

        A TableViewCell's text_label is a regular Label and can thus have its text_color changed:

        class MyDataSource(object):
            def tableview_cell_for_row(self, tv, section, row):
                cell = ui.TableViewCell()
                cell.text_label.text_color = (1.0, 0.0, 0.0, 0.0)
                cell.text_label.text = "I am red"
                return cell
        
        1 Reply Last reply Reply Quote 0
        • techteej
          techteej last edited by

          This creates a new cell, I want to modify an existing one.

          1 Reply Last reply Reply Quote 0
          • polymerchm
            polymerchm last edited by

            Here's a snippet of code in my flashcard program. highlight is a global that corresponds to the row needing highlighting in the items for the tableview.

            
            	def tableview_cell_for_row(self, tableview, section, row):
            		# Create and return a cell for the given section/row
            		cell = ui.TableViewCell()
            		cell.text_label.text = self.items[row]['title']
            		if row == highlight:
            			cell.text_label.text_color = 'red'
            		cell.accessory_type = self.items[row]['accessory_type']
            		return cell
            

            I also set a checkmark on this cell. Remember, this is called every time cell appears on the screen. As when it scrolls into view.

            1 Reply Last reply Reply Quote 0
            • vcr80
              vcr80 last edited by vcr80

              Is there a tutorial on how to create custom TableViewCells (with multiple subviews like labels, images, etc.) and then populate them with data?

              Ah - https://forum.omz-software.com/topic/1922/adding-a-label-to-tableviewcell-it-s-offset-by-one - seems to be a good starting point!

              1 Reply Last reply Reply Quote 1
              • First post
                Last post
              Powered by NodeBB Forums | Contributors