Custom Layer Class

Hi, i want to implement uiview with custom Catiledlayer for that it should be add class method layerclass like below:

    return [CATiledLayer class];

How can be done in moe?

What excactly are you trying to achieve? Please provide us more details, maybe there’s a better solution for what you are trying to do.

Hi Christian
I want to render huge uiview with custom drawing which use drawrect method of uiview in uiscrollview

In the default uiview use calayer as layer class, for that huge uiviews catiledlayer is recommended as i understand

to change uiviews default layer class i have to implement layerclass method, but there is no method in class

By the way, Glkview class extends from uiview and it has layerclass method. (But that class is depricated)

Hi there!

I’ve had a look into the Java binding class and there’s actually a layerClass method.
But as it seems it is static and therefor cannot be overridden by any sub class.

So probably you want to sub class UIView in ObjectiveC and create a custom UIView binding by copying the generated UIView java binding and remove / add respective @Annotations (removing @Generated on Type and adding @RegisterOnStartup. :arrow_left: not a 100% sure about these two, maybe @Noisyfox can say more about that :sweat_smile: )

I will try to generate custom Objective-C and bindings.

I think all you need to do is something like

public class HugeView extends UIView {

    // Some other codes

    public static Class layerClass() {
        return Class.fromJavaClass(CATiledLayer.class);

You don’t need to override the static method, just declare a new static method with the same selector and MOE should be able to take care of it.

This is similar to how you declare the alloc() method in your classes:

1 Like

Great solution :slight_smile:
Thanks again Noisyfox. :clap:

1 Like

Didn’t know about that nice sugar! Thx :slight_smile: