天天看點

認識Label控件

English:

program 程式

defined 定義

constructor 構造函數

platform 平台

deprecated 棄用

Deeper 深入

into 到..裡

formatting 格式化

property 屬性

using 使用

Xamrin 插件:

Thickness類:

在代碼中設定填充位置,請使用Thickness類,它一共有3個構造函數,分别對應昨天說的三種方式。

Read EBook Xamrin Chapter 3:

一 . Deeper into Text

這講述了Lable标簽使用的color、fonts and formatting

Lable标簽除了可以設定HorizontalOptions和VerticalOptions之外。

還可以設定HorizontalTextAlignment和VerticalTextAlignment。

HorizontalTextAlignment:文本在水準方向的位置:Center、Start、End
VerticalTextAlignment:文本在垂直方向的位置:Center、Start、End

在C#代碼中所對應的類是:TextAlignment 
           

二、LineBreakMode

NoWrap, //不換行,超出部分隐藏

WordWrap,//單詞為機關換行

CharacterWrap,//字元換行,即會出現單詞隔斷現象

HeadTruncation,//頭部截斷,省略頭部文本以...代替

TailTruncation,//尾部截斷

MiddleTruncation//中間截斷
           

三、BackgroundColors

值:支援RGB、HSL或者直接寫顔色名稱

BackgroundColor 背景顔色設定

TextColor 設定文本顔色

設定Android的主題顔色:
    https://developer.xamarin.com/guides/xamarin-forms/platform-features/android/appcompat/
           

四、設定字型

FontFamil屬性:值是字元串。

Node:字型必須在本機上有,比如 微軟雅黑,如果把程式放到其他電腦上,請注意該電腦是否裝了同樣的字型。

五、格式化字型

可以為Label設定多段不同的字型,格式化的意思并非删除,而是更改文本格式。

上代碼:

<Label HorizontalOptions="Fill" 
           VerticalOptions="Fill"
           BackgroundColor="Gray"
           HorizontalTextAlignment="End"
           VerticalTextAlignment="Center"
           LineBreakMode="WordWrap"
           TextColor="Yellow"
           FontFamily="微軟雅黑"
           Text="Hello Label">

        <Label.FormattedText>
            <FormattedString>
                <FormattedString.Spans>
                    <Span Text="Rad" ForegroundColor="Red" FontAttributes="Bold" >
                    </Span>
                    <Span Text="Default"></Span>
                    <Span Text="italic smail " FontAttributes="Italic" FontSize="Small"></Span>
                </FormattedString.Spans>

            </FormattedString>

        </Label.FormattedText>

    </Label>
           
一、建立HttpWebReuqest類:
  HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));

二、設定請求類型:
    request.ContentType= "application/json";

三、設定請求方法:
     request.Method = "POST";

四、發送請求,并傳回響應資料:

        using (WebResponse response = await request.GetResponseAsync())
        {

            using (Stream stream = response.GetResponseStream())
            {

                JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));

                return jsonDoc;
            }
        }
           
下一篇: android電腦

繼續閱讀