iOS Tutorial Designer Script & AutoScale tutorial

Discussion in 'iOS Tutorials' started by Erel, Nov 20, 2014.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Designer script feature allows you to write simple scripts that manage the user interface in the visual designer.

    The main advantage of the scripts over the program code is that you can see the script effect at design time.

    The process of loading a layout file is made of the following steps:
    - The best match variant is chosen.
    - The views are created. Anchors are applied at this point.
    - The general designer script and the variant script are executed.

    Later when the panel is resized:
    - The best match variant is chosen.
    - The views are resized. Anchors are applied at this point.
    - The general designer script and the variant script are executed.

    Note that anchors are applied before the scripts are executed (with one exception related to auto scaling).

    It is recommended to use as few variants as possible and instead to implement a flexible layout with anchors and the designer script. You can use the If condition in the script instead of multiple variants.

    AutoScale

    By default all scripts start with the AutoScaleAll keyword. Auto-scale works by comparing the page size to the chosen variant size. If the page size is larger then all the views will be slightly larger (including the text size). If the page size is smaller then the views will be slightly smaller.

    Reference


    The following properties are supported:

    - Left / Right / Top / Bottom / HorizontalCenter / VerticalCenter - Gets or sets the view's position. The view's width or height will not be changed.

    - Width / Height - Gets or Sets the view's width or height.

    - TextSize - Gets or sets the text size.

    - Text - Gets or sets the view's text.
    TextSize and Text properties are supported by: Button, Label, TextField and TextView.

    - Image - Sets the image file (write-only). Only supported by ImageView.

    - Visible - Gets or sets the view's visible property.

    Methods:

    - SetLeftAndRight (Left, Right) - Sets the view's left and right properties. This method changes the width of the view based on the two values.

    - SetTopAndBottom (Top, Bottom) - Sets the view's top and bottom properties. This method changes the height of the view based on the two values.

    In most cases you can use anchors instead of these two methods.

    Keywords:

    - Min / Max - Same as the standard Min / Max keywords.

    - AutoScaleAll - Autoscales all layout views.
    Example:
    Code:
    AutoScaleAll
    - AutoScaleRate - Sets the scaling rate, a value between 0 to 1. The default value is 0.3
    Example:
    Code:
    AutoScaleRate(0.2)
    - ActivitySize - Returns the approximate panel size measured in inches.

    - If ... Then condition blocks - Both single line and multiline statements are supported. The syntax is the same as the regular If blocks.

    - Landscape - Returns True if the current orientation is landscape.
    - Portrait - Returns True if the current orientation is portrait.

    Notes and tips

    - %x and %y values are relative to the view that loads the layout.

    - Variables - You can use variables in the script. You do not need to declare the variables before using them (there is no Dim keyword in the script).
     
    lemonisdead, pixet, Filippo and 2 others like this.
  2. cooperlegend

    cooperlegend Active Member Licensed User

    Is this for B4i or B4A ?
     
  3. klaus

    klaus Expert Licensed User

    For B4i !
    It's the same as for B4A.
     
    Erel likes this.
  4. ciginfo

    ciginfo Active Member Licensed User

    Hi,
    Why I do not see "Designer Scripts" on the Designer ?
     

    Attached Files:

  5. Erel

    Erel Administrator Staff Member Licensed User

    Which version are you using?
     
  6. ciginfo

    ciginfo Active Member Licensed User

    Version 1.0

    FD
     
  7. klaus

    klaus Expert Licensed User

    You must upgrade to V1.21
     
  8. ciginfo

    ciginfo Active Member Licensed User

    OK. What is the URL to download v1.21 please?
     
  9. klaus

    klaus Expert Licensed User

    I suppose you bought B4i, so you should have got an e-mail for the update.
    If not contact support@basic4ppc.com.
     
  10. ciginfo

    ciginfo Active Member Licensed User

    Yes I bought it but I do not remember the e-mail for the update. i'm looking for or I contact support@basic4ppc.com.
     
  11. klaus

    klaus Expert Licensed User

    Look in your spam folder.
     
  12. LucaMs

    LucaMs Expert Licensed User

    The main disadvantage is that you cannot debug it (use Log).

    I state that I start to use the new features only now, but I'm not certain that the mandatory anchor is not a problem.

    Given the results of my tests I would say that it is a problem; also, I may be wrong, but why then MS allows you to set the anchor to None?

    After many hours of trying, I was not able to adapt AnotherDatePicker so that:

    a) it can be added to an Activity by Designer, in the position and the desired dimensions;
    b) the same things but through code.


    I'm sorry for this negative post, but play with layouts, scripts, scaling,... makes me nervous :mad::mad::mad: :D
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    Note that you are posting in B4i forum. The default anchor settings (LEFT and TOP) is identical to the behavior you had in previous versions.
     
  14. LucaMs

    LucaMs Expert Licensed User

    Yes, I know, but I have not found this thread similar in B4A (have I not searched well?)

    Well, given that both you and Klaus say this, I will have to perform other tests and reconsider.

    Thanks Erel
     
Loading...