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

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:
B4X:
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
B4X:
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
 

Sviluppatori Liceo Giovio

Member
Licensed User
Apologies for the necro, but it doesn't appear to work. Here's the code I'm using.
B4X:
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
 
Upvote 0

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.
 

Attachments

  • IMG_1041.PNG
    IMG_1041.PNG
    151.8 KB · Views: 309
Upvote 0
Top