B4A Library iOS-SwitchView

This is an iOS type switch view for Android. It wraps this Github project. Posting the following (as it is all that you need):
1. B4A library files
2. B4A project

If you want to use it then you need to donate.

Library:
iosTypeSwitchView
Version:
1
  • SwitchView
    Events:
    • switch_changed (checked As Boolean)
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • isChecked As Boolean
      return the state of switch view
    • toggle (isChecked As Boolean)
      if set true , the state change to on;
      if set false, the state change to off
    Properties:
    • Background As Drawable
    • BigCircleInnerColor As Int [write only]
    • BigCircleOutlineOffColor As Int [write only]
    • BigCircleOutlineOnColor As Int [write only]
    • Checked As Boolean [write only]
      if set true , the state change to on;
      if set false, the state change to off
    • Color As Int [write only]
    • DisableBorderColor As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • ShadowColor As Int [write only]
    • StateOffRightColor As Int [write only]
    • StateOnLeftColor As Int [write only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int

Sample Code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: iosTypeSwitchView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

'#AdditionalRes: ..\LibRes

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private sv1 As SwitchView
    Private Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
  
    sv1.StateOffRightColor = Colors.White
    sv1.StateOnLeftColor = Colors.Cyan
    sv1.BigCircleInnerColor = Colors.Black
    sv1.DisableBorderColor = Colors.Magenta
    sv1.ShadowColor = Colors.White
  
    sv1.BigCircleOutlineOffColor = Colors.Yellow
    sv1.BigCircleOutlineOnColor = Colors.Magenta
  
    Label1.Text = "OFF"

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub sv1_switch_changed(checked As Boolean)
  
    Log("state = " & checked)
    If checked Then
        Label1.Text = "ON"
        Label1.TextColor = Colors.green
    Else
        Label1.Text = "OFF"
        Label1.TextColor = Colors.red
    End If
  
End Sub

Sure you will figure out the use of the colors - the names are self explanatory.
It will raise an event in the B4A project when the switch changes state.

1.png


2.png
 

Attachments

  • iosTypeSwitchViewLibFiles.zip
    11.9 KB · Views: 231
  • b4aIOSTypeSwitchView.zip
    8.3 KB · Views: 207
Last edited:

peacemaker

Expert
Licensed User
Longtime User
"Trail period is expired - sorry".
Is it correct - the lib is limited ? Or i'm wrong and it's text from some other lib ?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Seeing that it is workers day tomorrow- lib files attached without any time limit...;)
 

Attachments

  • iosTypeSwitchView.xml
    11.2 KB · Views: 181
  • iosTypeSwitchView.jar
    11.2 KB · Views: 181
Top