iOS Question iTabstrip - Change background color of the selected label?

Discussion in 'iOS Questions' started by Sviluppatori Liceo Giovio, Apr 18, 2019.

  1. Sviluppatori Liceo Giovio

    Sviluppatori Liceo Giovio Member Licensed User

    Is it possible to change the background color of the label corresponding to the currently selected page in the _Pageselected event?
    I do it in B4A using this code:
    Code:
    Dim i As Int
        
    For Each lbl As Label In GetAllTabLabels(TabStrip1)
            
    If i = Position Then
                lbl.SetColorAnimated(
    200, AccentColor, Colors.RGB(15,105,255))
            
    Else
                lbl.Color = AccentColor
            
    End If
            i = i + 
    1
        
    Next
    Where getalltablabels is
    Code:
    Public Sub GetAllTabLabels (tabstrip As TabStrip) As List
        
    Dim jo As JavaObject = tabstrip
        
    Dim r As Reflector
        r.Target = jo.GetField(
    "tabStrip")
        
    Dim tc As Panel = r.GetField("tabsContainer")
        
    Dim res As List
        res.Initialize
        
    For Each v As View In tc
            
    If v Is Label Then res.Add(v)
        
    Next
        
    Return res
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Sviluppatori Liceo Giovio

    Sviluppatori Liceo Giovio Member Licensed User

  4. Erel

    Erel Administrator Staff Member Licensed User

    Worth posting the link next time as it is relevant (took me a while to find it).

    You can use cs.BackgroundColor to change the text background color.
     
    Johan Hormaza likes this.
  5. Sviluppatori Liceo Giovio

    Sviluppatori Liceo Giovio Member Licensed User

    I'll keep that in mind for next time. Thanks.
     
  6. Sviluppatori Liceo Giovio

    Sviluppatori Liceo Giovio Member Licensed User

    Apologies for the necro, but it doesn't appear to work. Here's the code I'm using.
    Code:
    Sub TabStrip1_PageSelected (Position As Int)
        
    Log($"Current page: ${Position}"$)
        
    Dim i As Int

       
        
    For i = 0 To TabPages.Size - 1
           
            
    Dim p As Page = TabPages.Get(i)
            
    Dim lbl As Label = p.TitleView
            
    Log(lbl.AttributedText.ToString)
           
            
    Dim clr As Int
            
    Dim cs As CSBuilder
            
    If i = Position Then
                SetAttributedTitle(p, cs.Initialize.BackgroundColor(
    Colors.RGB(15,105,255)).Color(Colors.White).Append(lbl.AttributedText.ToString).PopAll)
            
    Else
                SetAttributedTitle(p, cs.Initialize.BackgroundColor(AccentColor).Color(
    Colors.White).Append(lbl.AttributedText.ToString).PopAll)
            
    End If
           
           
           
        
    Next
    End Sub
     
  7. Erel

    Erel Administrator Staff Member Licensed User

  8. Sviluppatori Liceo Giovio

    Sviluppatori Liceo Giovio Member Licensed User

    Well I'm dumb. Thanks. Is there a way to make the label's background fit the entire "section" of the tabstrip it has assigned?
    I've attached a screenshot to show what I'm talking about.
     

    Attached Files:

  9. Erel

    Erel Administrator Staff Member Licensed User

    Try to change the label color instead of using attributed string.
     
  10. Sviluppatori Liceo Giovio

    Sviluppatori Liceo Giovio Member Licensed User

    Nothing seems to happen.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    It might be impossible to change it like you want.
     
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