Add control dynamically

  1. 4 months ago

    how can i add a button or any other control dynamically (by code)?

  2. Marc

    Mar 13 User since 2018

    I don't think that's possible (yet?).

    I personally would especially like that in a Flex enabled container, because Flex is easier to use (regarding positioning) when adding controls dynamically.

  3. Edited 4 months ago by Luiz D'Aniello

    @Marc I don't think that's possible (yet?).

    I personally would especially like that in a Flex enabled container, because Flex is easier to use (regarding positioning) when adding controls dynamically.

    I discovered. If you use a View, you can use addSubView to add.

    func Load():
    var pb=Button(ButtonType.RoundedRect);
    pb.title="TEST";
    pb.backgroundColor=Color("a9aaaa");
    self.addSubview(pb);
  4. Marc

    Mar 13 User since 2018
    Edited 4 months ago by Marc

    @Luiz D'Aniello I discovered. If you use a View, you can use addSubView to add.

    func Load(): var pb=Button(ButtonType.RoundedRect); pb.title="TEST"; pb.backgroundColor=Color("a9aaaa"); self.addSubview(pb);

    Ah, of course. I only checked the Creo View class and forgot to look at the parent classes (duh ...). But still, from my experience, I think using Flex would be much easier for positioning than using lay-out constraints from code.

or Sign Up to reply!