Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionViewCell Definition F#

How would I translate the following C# code into F#:

public class AnimalCell : UICollectionViewCell
{
[Export ("initWithFrame:")]
  public AnimalCell (RectangleF frame) : base (frame) {}
}

I tried following the example in the below link, however, I do not know how to proceed next: Overriding Constructors in F#

What I have come up with up till now is this:

[<Register ("AnimalCell")>]
type AnimalCell (handle: IntPtr) as this = 
    inherit UICollectionViewCell (handle)

where would I add the Export as well as the parameters? I know I should use new() but I'm not sure how to proceed.

like image 551
Alk Avatar asked Jan 29 '26 17:01

Alk


1 Answers

Something like this will get you started:

F# UICollectionViewCell subclass

[<Register ("AnimalCell")>]
type AnimalCell =   
    inherit UICollectionViewCell

    [<DefaultValue>] static val mutable private id : NSString
    static member init = 
        printfn "Initializing AnimalCell."
        AnimalCell.id <- new NSString("animalCell")

    [<Export("init")>]
    new() = { inherit UICollectionViewCell() } then AnimalCell.init
    [<Export("initWithFrame:")>]
    new(frame: CGRect) = { inherit UICollectionViewCell(frame) } then AnimalCell.init
    [<Export("initWithCoder:")>]
    new(coder: NSCoder) = { inherit UICollectionViewCell(coder) } then AnimalCell.init

    new(handle: IntPtr) = { inherit UICollectionViewCell(handle) } then AnimalCell.init

    override this.ReuseIdentifier = AnimalCell.id
like image 177
SushiHangover Avatar answered Jan 31 '26 08:01

SushiHangover



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!