B4i Library iSwiftyButton

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.

SS-2017-01-24_12.12.04.png


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

  • iSwiftyButton.zip
    52.5 KB · Views: 123
Last edited:

so27

Active Member
Licensed User
Longtime User
Very beautiful! Is this also soon for B4A?
 

tufanv

Expert
Licensed User
Longtime 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
Longtime 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?
 

miker2069

Active Member
Licensed User
Longtime User
So this is very cool - so we can either choose to include Obj-C or Swift Libs in a project.
 

Erel

B4X founder
Staff member
Licensed User
Longtime 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

SS-2017-01-25_08.15.42.png
 

tufanv

Expert
Licensed User
Longtime 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

SS-2017-01-25_08.15.42.png
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
Longtime 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