iOS Question Set cell height programmatically for a single cell in TableView?

Discussion in 'iOS Questions' started by Pendrush, Mar 18, 2015.

  1. Pendrush

    Pendrush Well-Known Member Licensed User

    Anyone know?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can use CustomListView instead of TableView to create cells with different height.
     
  3. Pendrush

    Pendrush Well-Known Member Licensed User

    Actually I'm using ExpandableTableView and I need to reduce the height of the first child cell. I can't use CustomListView.

    Cell height Object-C solution
    http://stackoverflow.com/a/9824063
    but I'm unable to implement it
     
  4. davepamn

    davepamn Active Member Licensed User

    you can't set a single table cell height

    instead, set the tableview row height

    Code:
    Private tvContracts As TableView

    tvContracts.Initialize(
    "tvContracts",False)
     tvContracts.RowHeight=
    50dip
     
  5. davepamn

    davepamn Active Member Licensed User

    Code:
    Private Sub Createitem2(tvTableview As TableView, sLine1Value As String,sLine2Value As String, iAlpha As Int, iRed As Int, iGreen As Int, iBlue As Int,iFontSize As Int,iFontColor As Int) As Panel

        
    Dim oPanel As Panel

        
    Dim lblLine1Data As Label

        
    Dim lblLine2Data As Label

        
    Dim iOffset As Int=0

        oPanel.Initialize(
    "2ItemPanel")

        lblLine1Data.Initialize(
    "line1data")

        lblLine1Data.Text=sLine1Value
        
        lblLine1Data.Tag=sLine1Value

        lblLine1Data.color=
    Colors.ARGB(iAlpha,iRed,iGreen,iBlue)

        lblLine1Data.Font=
    Font.CreateNew(iFontSize)

        lblLine1Data.TextColor=iFontColor

        iOffset=tvTableview.RowHeight/
    2

        oPanel.Width=
    100%x

        oPanel.Height=tvTableview.RowHeight

        oPanel.AddView(lblLine1Data,
    0,0,100%x,tvTableview.RowHeight/2)

        
    'Line 2

        lblLine2Data.Initialize(
    "line2data")

        lblLine2Data.Text=sLine2Value

        lblLine2Data.Tag=sLine2Value

        lblLine2Data.color=
    Colors.ARGB(iAlpha,iRed,iGreen,iBlue)

        lblLine2Data.Font=
    Font.CreateNew(iFontSize)

        lblLine2Data.TextColor=iFontColor

        oPanel.AddView(lblLine2Data,
    20dip,iOffset,100%x ,tvTableview.RowHeight/2)

        
    Return(oPanel)

    End Sub
    You can create a panel then add two dynamically create labels whose height is half the tableview row height.
     
    Last edited: Mar 19, 2015
    kemanlam likes this.
  6. Pendrush

    Pendrush Well-Known Member Licensed User

    Than you for reply. I have already made something similar, what is problem...
    Categorie(s) have one line of text, their child (sub cats) are in 3 line of text with image on left ....
    My row height is minimum height for sub cats, but then categories with only one line of text (even centered with lager font size) have a lot of space above and below text.
     
  7. davepamn

    davepamn Active Member Licensed User

    Set the Rowheight to the height of three of your labels then place each label in a panel offsetting by the height of the label. Return the panel to the table cell for the tableview.

    In my example, I used two labels to simulate AddTwoLines
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice