Button and view colours (iOS)

ok, but which parameters and return type needs to be set? I’m getting a syntax error.

Here’s the breakdown

Sub setColor(extends b As iOSButton, back As color, border as color, radius as double)

“Sub” means there is no return value “Function” would mean there’s a return value
“setColor” is the name of the method
The part in the parenthesis id the parameters
Then the part before “End Sub” is the code.

Take a look at this.

Vincent,
Every time you see code which starts with Sub - it means it is a method.

Basically, only the code between the first and last line is the actual code. (The first line simply names the method and defines the parameters required).

Therefore, in your example, you need to create a new method, call it setColor (as defined in the first line), then paste in the code (minus the very first and very last lines).

Then all you need to do is place the code which was inside the ( ) of the now removed first line, into the paramaters area in the right-hand side Inspector (as is highlighted in Jim’s post above).

Functions are exactly the same principle - with the exception that there will be extra code in the very first line, which needs to be entered into the Return Type in the inspector.

Basically, they are both methods, but a function returns a value to the calling code (as opposed to a normal method, which does not).

Hope that helped.

Thanks all, I figured it out. Here’s a sample project, based on the above code, for others to enjoy:
http://shared.info/iOS-Buttons.zip

Vincent … thanks for the code works great and will be the basis for many an app. For some reason the code works great on the Iphone5 but not on the IPAD Air. Works okay on the simulator but not when I set up a test device and actually download it.

What’s going on/what am I missing?

[quote=172780:@Steve Young]Vincent … thanks for the code works great and will be the basis for many an app. For some reason the code works great on the Iphone5 but not on the IPAD Air. Works okay on the simulator but not when I set up a test device and actually download it.

What’s going on/what am I missing?[/quote]

The iPhone 5 is 32 bit like the simulator, and the iPad Air is 64. That probably explains.

Could be … So what do I do to fix it?

You look at the declares into the colored buttons class and try to figure where it is not 64 bit compatible. Most of the time, Integers are the problem. In 32 bit, Integers are UInt32, whereas in 64 bit they are UInt64. You want to make sure to replace all Integers by uInt32, and try again. Otherwise, you will need to contact Vincent Verweij and ask him if he has updated his code to 64 bit.

I’m not sure how to fix this. It was Jim McKay’s code btw, I just wrapped it up.

Sorry ; since you posted it I assumed. Most of Jim’s code was created for the simulator in 32 bits and apparently he has not got to 64 bit yet.

I’m not so sure there are no “Dim XX as UInt32” type statements. None of the variables seem to be 32/64 bit specific … far was I can tell.

I think the problem lies here:

Declare Function decl_GetColorWithRGBA lib "UIKit" selector "colorWithRed:green:blue:alpha:" (UIColorClassRef As Ptr, red As Single, green As Single, blue As Single, alpha As Single) As Ptr

colorWithRGBA demands CGFloats, so for 64 bit you must pass doubles instead of singles.

EDIT: And no, you don’t need to change integers. They are automatically 32 or 64 bit long.

EDIT II: Try this instead:

' UIKit Declare to create a color object #if Target64Bit Declare Function decl_GetColorWithRGBA lib "UIKit" selector "colorWithRed:green:blue:alpha:" (UIColorClassRef As Ptr, red As Double, green As Double, blue As Double, alpha As Double) As Ptr #elseif target32bit Declare Function decl_GetColorWithRGBA lib "UIKit" selector "colorWithRed:green:blue:alpha:" (UIColorClassRef As Ptr, red As Single, green As Single, blue As Single, alpha As Single) As Ptr #endif ' Here is the corresponding Xojo call, where we create a flashy green color dim myUIColorObject As ptr = decl_GetColorWithRGBA(theUIColorClassRef, (33.0/255.0), (209.0/255.0), (57.0/255.0), 1.0)

Ulrich … You are the man! Proost

Does it work? I couldn’t try it on a device. Glad to hear it!

Generally for iOS 64bit, at least as far as I can tell: There’s mostly no need to worry about integers. If a function does not demand a certain type (like Int32 or UInteger …), you don’t need to do anything, they are fail safe thanks to the compiler (and the Xojo engineers).

But many API methods make use of structures like NSRect, NSSize etc. which need to be done in 2 versions, and the same is true for the frequently used CGFloat. I believe the best way is to define them in their 64bit types for general handling and add conversions to the 32bit types that need to be used internally on 32bit systems.

(As an example: This is how I handle the CALayer ContentsCenter property in my MacOSControls lib:)

Get #if TargetMacOS #if target32bit Declare Function contentsCenter lib AppKit selector "contentsCenter" (id as ptr) as NSRect32Bit return contentsCenter(id).toNSRect #elseif Target64Bit Declare Function contentsCenter lib AppKit selector "contentsCenter" (id as ptr) as NSRect return contentsCenter (id) #endif #endif End Get

with a conversion module for rects containing methods like

[quote]Function toNSRect(extends aRect32 as NSRect32Bit) As NSRect
dim result as NSRect
result.Size_ = aRect32.Size_.tonssize
result.Origin = aRect32.Origin.tonspoint
return result
End Function
[/quote]

The toNSSize and toNSPoint methods doing the real conversion between single and double – which means just pushing them over to the other struct size.

If you check existing declares for CGFloat and NS/CGRect etc. types (there’s no need to have CGRect as well as NSRect and so on, all the rect, size and points structures are the same, but come in two sizes), it should be fairly easy to adapt them for 64bit.