B4i Library iSwiftyButton

Erel

Administrator
Staff member
Licensed User
Don't use this library. Better option: https://www.b4x.com/android/forum/threads/b4x-xui-swiftbutton.95180/

This is a wrapper for https://github.com/TakeScoop/SwiftyButton.



The PressableButton should be added as a custom view with the designer.

The open source project is a Swift project. This is the first library that wraps a Swift project.
The wrapper code is available here: https://github.com/AnywhereSoftware/B4i_iSwiftyButton

You should also copy the framework to the Mac Libs folder if you are using a local builder.
Note that there is no simulator binary included in the framework.
The minimum version for Swift libraries is iOS 8:
B4X:
#MinVersion: 8
Edit: v1.01 is released. Fixes a small issue.

The framework is available here:
Xcode 9: www.b4x.com/b4i/files/SwiftyButton.framework.zip
Xcode 10: www.b4x.com/b4i/files/Xcode10SwiftFrameworks.zip
You should download it directly to your Mac.
 

Attachments

Last edited:

tufanv

Expert
Licensed User
Thanks Erel. These may seem little visual things but they are very good for our projects !. If you will have time in the future , we wait for these little but powerfull things in the future.
 

miker2069

Active Member
Licensed User
If I understand correctly, iOS stock buttons are pretty blah, and there's alot of work to customize them - this would make it about as easy as it can be even when compared to developing with swift itself. I still haven't tinkered with swift yet.

Maybe this is off topic but will be B4i eventually support custom swift libraries? I really am not up to speed on where Apple is with Objective C and Swift, are they pushing devs to Swift or are they happily co-existing?
 

Erel

Administrator
Staff member
Licensed User
You can create an Objective C wrapper that references a Swift framework.
You can also reference the Swift framework directly and use NativeObject or inline OBJC to access it.

For example this code creates a FlatButton. iSwiftyButton library (the wrapper) is not used.
B4X:
#AdditionalLib: SwiftyButton.framework.swift.3
#MinVersion: 8
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page

End Sub

Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.Color = Colors.White
   NavControl.ShowPage(Page1)
   Dim b As Button = CreateFlatButton(Colors.Red)
   Page1.RootPanel.AddView(b, 10, 10, 200, 100)
   b.Text = "sdf"
End Sub

Sub CreateFlatButton (clr As Int) As Button
   Dim no As NativeObject
   no = no.Initialize("SwiftyButton.FlatButton").RunMethod("alloc", Null)
   no = no.RunMethod("initWithFrame:", Array(no.MakeRect(0, 0, 0, 0)))
   no.SetField("color", no.ColorToUIColor(clr))
   Return no
End Sub
 

tufanv

Expert
Licensed User
You can create an Objective C wrapper that references a Swift framework.
You can also reference the Swift framework directly and use NativeObject or inline OBJC to access it.

For example this code creates a FlatButton. iSwiftyButton library (the wrapper) is not used.
B4X:
#AdditionalLib: SwiftyButton.framework.swift.3
#MinVersion: 8
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page

End Sub

Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.Color = Colors.White
   NavControl.ShowPage(Page1)
   Dim b As Button = CreateFlatButton(Colors.Red)
   Page1.RootPanel.AddView(b, 10, 10, 200, 100)
   b.Text = "sdf"
End Sub

Sub CreateFlatButton (clr As Int) As Button
   Dim no As NativeObject
   no = no.Initialize("SwiftyButton.FlatButton").RunMethod("alloc", Null)
   no = no.RunMethod("initWithFrame:", Array(no.MakeRect(0, 0, 0, 0)))
   no.SetField("color", no.ColorToUIColor(clr))
   Return no
End Sub
I will try to implement another example just referencing the swift framework. First I wanted to try this code but where is the framework file ? (
#AdditionalLib: SwiftyButton.framework.swift.3)
 

tufanv

Expert
Licensed User
Were you able to submit your app to the app store with the swift library?


The framework is already available on the hosted builders. You do not need it locally.
Not yet, I will change back to swiftybutton again.
 
Top