iOS - Forms - XAML : How do I set the width and height of a view ?(Label, Button, ..)

FrankSimtob.0336FrankSimtob.0336 CAMember
edited November 2015 in Xamarin.Forms

In the xaml code below, how do I make Label and Entry occupy a certain width and height ? (in % of the screen or pixels)
At the moment, the width of Entry depends on how long the text in Label is.
More generally: Is there a document that shows ALL the properties of the views with ALL the possible values?

<StackLayout Spacing="2" HorizontalOptions="CenterAndExpand" VerticalOptions="Start" Padding="20" >
            
    <Label x:Name="appId" 
 Text="Hello"
   TextColor="Blue"
   BackgroundColor="Yellow" />

    <Entry x:Name="code" />
    
</StackLayout>


Thank you

Answers

  • DavidDancyDavidDancy AUMember ✭✭✭✭

    You can use WidthRequest and HeightRequest to request a size. Depending on your layout options though you may or may not get the size you requested.

  • Thank you DavidDancy
    I tried WidthRequest and HeightRequest (because they showed up in the "autocomplete") and they had no effect on the size of the Label or Entry

  • I changed HorizontalOptions to "Center"
    I can set the width of Label, but Enter gets the same width as Label even though the RequestedWidth parameters are different. Could any one give me some insight into this?
    Thank you

  • DavidDancyDavidDancy AUMember ✭✭✭✭

    Did you try setting the WidthRequest and/or HeightRequest on the Label and Entry elements? For example:

        <StackLayout Spacing="2" HorizontalOptions="CenterAndExpand" VerticalOptions="Start" Padding="20" >
            
            <Label x:Name="appId" 
WidthRequest="200" HeightRequest="100" 
            Text="Hello"
   TextColor="Blue"
   BackgroundColor="Yellow" />

            <Entry x:Name="code" WidthRequest="250" />
    
        </StackLayout>

    
  • DavidDancy - I did not set "HeightRequest". I set "WidthRequest" ="300" for Label and ="60" for Entry
    They were both the same width on the page (simulator). I tried different numbers. Entry and Label are always the same width.

Sign In or Register to comment.