iOS Question B4A to B4I Porting Help

Mashiane

Expert
Licensed User
Longtime User
Hi there

I need some help with my code, Im porting a B4A app to B4I. I intend to post some code here as questions and possibly answers that will work. Here is my first code snippet conversion of which I need help with. Can someone please advise please?

NB: I have developed a B4J app to convert bal2bil and also some source code:
https://www.b4x.com/android/forum/threads/jmashbal2bil-convertor.68949/

B4X:
Purpose: Change the backcolor, textcolor, border, bordersize around buttons
B4A Code
' pass this to a button to convert its textcolor, backcolor, bordersize and the cornerRadius size.
Sub Fancy_Button(btn As Button, backColor As Int, textColor As Int, borderSize As Int, cornerRadius As Float, borderColor As Int)
    Dim dr As ColorDrawable
    dr.Initialize2(backColor, cornerRadius, borderSize, borderColor)
    btn.Background = dr
    btn.TextColor = textColor
    btn.Invalidate
End Sub

' usage
Public PowderBlue As Int = Colors.rgb(154,217,234)
Sub Button_PowderBlueBlack(btn As Button)
   Fancy_Button(btn,PowderBlue,Colors.black,2,2%x, Colors.black)
End Sub

Solution: B4i Code
Sub Fancy_Button(btn As Button, backColor As Int, textColor As Int, borderSize As Int, cornerRadius As Float, borderColor As Int)
   'state: 0 = normal, 1 = pressed, 2 = disabled
   Dim no As NativeObject = btn
   Dim state As Int = 0
   ' set text color
   btn.CustomLabel.TextColor = textColor
   ' set back color
   btn.Color = backColor
   ' set the border
   btn.SetBorder(borderSize,borderColor,cornerRadius)
  no.RunMethod("setTitleColor:forState:", Array(no.ColorToUIColor(textColor), state))
End Sub
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
B4X:
B4A
StartActivity(frmX)

B4I
'Create a Code Module e.g frmX and add Show Method
'Dim pg as Page

Public Sub Show
If pg.IsInitialized = False Then
     pg.Initialize("pg")
     pg.RootPanel.LoadLayout("xxx")
     pg.RootPanel.Color = Colors.White
   End If
  pg.Title = sTitle
  pg.HideBackButton = bHideBackButton
   Main.ShowPage2(pg,true)
End Sub

then call
frmX.Show
 
Last edited:
Upvote 0
Top