UI 富文本 利用簡單的標記標籤來樣式化字串的部分,包括粗體、斜體、下劃線、填充顏色、描邊變化等。您可以將樣式標籤應用於 TextLabel、TextButton 和 TextBox 物件。
啟用富文本
您必須通過其 RichText 屬性在每個物件上啟用富文本,這可以在 屬性 窗口中進行,或通過在 LocalScript 中將屬性設置為 true。

local title = Instance.new("TextLabel")
title.RichText = true
title.Text = "使用 <b>粗體標題</b>"支持的標籤
富文本標籤類似於 XML/HTML 標籤,您必須在格式化文本周圍包含開啟和關閉標籤。
<b>格式化文本</b>
您也可以將標籤嵌套在一起,只要您以相反的順序關閉它們。
<b><i><u>格式化文本</u></i></b>
字體顏色
<font color=""> </font>
我想要 <font color="#FF7800">橙色</font> 糖果。
我想要 <font color="rgb(255,125,0)">橙色</font> 糖果。

字體大小
<font size=""> </font>
<font size="40">這是大字。</font> <font size="20">這是小字。</font>

字體樣式
<font face=""> </font>
<font face="Michroma">這是 Michroma 字體。</font>

字體家族
<font family=""> </font>
<font family="rbxasset://fonts/families/Michroma.json">這是 Michroma 字體。</font>

字體粗細
<font weight=""> </font>
這是正常的。 <font weight="heavy">這是粗的。</font>
這是正常的。 <font weight="900">這是粗的。</font>

字體透明度
<font transparency=""> </font>
文本在 <font transparency="0.5">50% 透明度</font>。

描邊
<stroke> </stroke>
| 參數 | 等效屬性 | 示例值 |
|---|---|---|
| color | UIStroke.Color | "rgb(255,125,0)"、"#FF7800" |
| thickness 或 th | UIStroke.Thickness | "1"、"4"、"0.5" |
| transparency 或 tr | UIStroke.Transparency | "0"、"0.5"、"1" |
| joins | UIStroke.LineJoinMode | "round"、"bevel"、"miter" |
| sizing | UIStroke.StrokeSizingMode | "fixed"、"scaled" |
您贏得了 <stroke color="#00A2FF" thickness="2" transparency="0.25" joins="miter">25 顆寶石</stroke>。

粗體
<b> </b>
文本為 <b>粗體</b>。

斜體
<i> </i>
文本 <i>斜體</i>。

下劃線
<u> </u>
文本 <u>下劃線</u>。

刪除線
<s> </s>
文本帶有 <s>刪除線</s>。

換行
<br/>
這句話之後會換行。<br/>下一句...

大寫
<uppercase> </uppercase>
<uc> </uc>
<uppercase>大寫</uppercase> 使單詞讀起來響亮!
<uc>大寫</uc> 使單詞讀起來響亮!

小型大寫
<smallcaps> </smallcaps>
<sc> </sc>
我的名字是 <smallcaps>Diva Dragonslayer</smallcaps>。
我的名字是 <sc>Diva Dragonslayer</sc>。

標記
<mark> </mark>
文本 <mark color="#009966" transparency="0">高亮顯示</mark>。

註解
<!-- -->
這之後是註解...<!--這不會出現在最終文本中--> 現在有更多文本...

轉義形式
如果您想渲染某些字符,如 < 或 >,並將它們排除在富文本標籤之外,您可以將它們寫成 轉義形式。
| 字符 | 轉義 | 示例 | 結果 |
|---|---|---|---|
| < | < | 10 < 100 | 10 < 100 |
| > | > | 100 > 10 | 100 > 10 |
| " | " | Meet "Diva Dragonslayer" | Meet "Diva Dragonslayer" |
| ' | ' | Diva's pet is a falcon! | Diva's pet is a falcon! |
| & | & | Render another escape form <b>&lt;</b> by escaping an ampersand | Render another escape form < by escaping an ampersand |