iOS filled button

Hi!

How do i “fill” an iOS button on xojo IDE?

i want something like this:

Tks!

Alex

In the opening event:

me.SetBackgroundColorXC(&c26b2ff) //whatever color
me.SetCornerRadiusXC(8) //whatever radius

where these methods are in the IOSLib package

Public Sub SetBackgroundColorXC(Extends bt As MobileButton, value As color)
Declare Function NSClassFromString Lib “Foundation” (className As CFStringRef) As Ptr
Declare Function colorWithRGBA Lib “UIKit.framework” Selector “colorWithRed:green:blue:alpha:” ( UIColorClassRef As Ptr, red As CGFloat, green As CGFloat, blue As CGFloat, alpha As CGFloat) As Ptr

Declare Function view Lib “UIKit.framework” Selector “view” (UIViewController As Ptr) As Ptr
Declare Sub setBackgroundColor Lib “UIKit.framework” Selector “setBackgroundColor:” (UIView As Ptr, UIColor As Ptr)
Var UIColorClassPtr As Ptr =  NSClassFromString(“UIColor”)
Var colorPtr As ptr = colorWithRGBA(UIColorClassPtr, (value.red / 255.0), (value.Green / 255.0), (value.Blue / 255.0), (1.0-value.Alpha/255.0))
Var viewPtr As Ptr = bt.HandleSetBackgroundColor(viewPtr, colorPtr)
End Sub

and


Public Sub SetCornerRadiusXC(extends ctrl As MobileUIControl, radius As Double)
Declare Function layer_ Lib “UIKit.framework” selector “layer” (id As ptr) As Ptr
Var layer As ptr = layer_(ctrl.Handle)
Declare Sub setCornerRadius Lib “QuartzCore.framework” selector “setCornerRadius:” (id As ptr, value As CGFloat)
setCornerRadius layer, radius
if ctrl isa MobileButton then
Var insets As ExtensionsXC.xcUIEdgeInsets
insets.Left = radius
insets.Top = 0
insets.Right = radius
insets.Bottom = 0

MobileButton(ctrl).SetButtonInsetsXC(insets)
else
Declare Sub clipsToBounds Lib "UIKit.framework" selector "setClipsToBounds:" (id As ptr, value As Boolean)
clipsToBounds(ctrl.Handle, True)
end if
End Sub
1 Like

what i did wrong?

do you use the GitHub - jkleroy/iOSDesignExtensions: 100+ functions to extend iOSControls design ?

2 Likes

As Valdemar says, best include the full IOSDesign extensions , which is an amazing piece of work, and arguably essential if you want to use Xojo on IOS

I pasted parts of it above in a hurry as I thought maybe you could use just the minimal code, but missed the xcUIEdgeInserts declaration, which is a structure of 4 cgfloats

However, you will definitely be better off long term including the whole IOSDesignExtensions - I keep finding more and more ‘things I would like to be able to do’ which are already solved there.

1 Like

thank you very much guys!