<div id="article_content" class="article_content clearfix">
<link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
<div id="content_views" class="htmledit_views">
<p id="main-toc"><strong>目录</strong></p>
<p id="-toc" style="margin: 0px;"> </p>
<p style="margin-left:0px;"> </p>
<p id="" style="margin: 0px 0px 2px; padding-left: 24px;"><a href="#t0" target="_self">Label组件简介</a></p>
<p id="" style="margin: 0px 0px 2px; padding-left: 24px;"><a href="#t1" target="_self">Label组件常用属性</a></p>
<hr id="hr-toc">
<h1><a name="t0"></a> </h1>
<h1 id="wow2"><a name="t1"></a>Label组件简介</h1>
<p>在UI界面中,我们经常看到一些文字描述,说明。这些文字显示就需要用到Label控件了</p>
<p> </p>
<h1 id="Label%E7%BB%84%E4%BB%B6%E5%B8%B8%E7%94%A8%E5%B1%9E%E6%80%A7"><a name="t2"></a>Label组件常用属性</h1>
<figure class="image has">
<img alt="" height="684" src="https://img-blog.csdnimg.cn/20190529195920914.png" width="279">
<figcaption>
<u>Label组件Inspector面板</u>
</figcaption>
</figure>
<h3 id="wow4"><a name="t3"></a> </h3>
<p><strong><span style="color:#f33b45;">Font</span>: </strong>字体</p>
<p>NGUI的Label组件支持NGUI插件自带的几种字体和Unity本身的字体。我们可以将TTF格式字体文件放置到Unity的Assets目录中进行使用。<br> 当然我们也可以使用Atlas Maker创建动态字体和静态字体(就是把文字做成图片,运行效率要比动态字体高).</p>
<p><strong><span style="color:#f33b45;">Fort Size</span>: </strong>字体的大小 <strong><span style="color:#f33b45;">Normal</span> : </strong>为正常的字体 <strong><span style="color:#f33b45;">Bold</span>: </strong>加粗字体 <strong><span style="color:#f33b45;">Italic</span>: </strong>倾斜字体 <strong><span style="color:#f33b45;">Bold and Italic</span>: </strong>加粗并倾斜字体</p>
<p><strong><span style="color:#f33b45;">Text: </span></strong>要显示的内容</p>
<p><strong><span style="color:#f33b45;">Overflow</span>: </strong>针对文字的内容过多的不同显示效果设置。<br> * Shrink Content 文字根据文字框的内容自动缩放文字大小(文字自适应文字框)<br> * Clamp Content 文字大小将被固定,不随文字框大小而改变文字大小,如果文字框太小,文字将不可见<br> * Resize Freely 文字框空间会与文字所需要的最小空间保持一致,且文字框大小不可调节<br> * Resize Height 高度会自适应,只能调节宽度</p>
<p id="wow8"><span style="color:#f33b45;"><strong>Alignment:</strong></span>对齐方式</p>
<p>Label标签对齐方式:左对齐/居中对齐/右对齐/自动扩展(文本会和文本框的宽度保持一致)</p>
<p>*Automatic:自动对齐</p>
<p>*Left:左对齐</p>
<p>*Centre:居中对齐</p>
<p>*Right:右对齐</p>
<p>*Justified:自动扩展</p>
<p id="wow9"><span style="color:#f33b45;"><strong>Keep Crisp: </strong></span>动态字体锐化</p>
<p id="wow10"><span style="color:#f33b45;"><strong>Gradient: </strong></span>文字的渐变</p>
<p id="wow11"><span style="color:#f33b45;"><strong>Effect: </strong></span>文字的特效(可以是文字呈现出投影和描边效果)</p>
<p><span style="color:#f33b45;"><strong>Float Spacing :</strong></span>是否开启字间距(用于控制文字中字与字的间距)</p>
<p><span style="color:#f33b45;"><strong>Max Lines: </strong></span>设置文本显示的最大行数 0 表示无行</p>
<p id="wow14"><span style="color:#f33b45;"><strong>BBCode : </strong></span>是否支持颜色代码字体</p>
<p>以上就是UILabel常用属性</p>
<p>额外的一些知识:</p>
<h3><a name="t4"></a><span style="color:#f33b45;"><strong>Label中的超链接出来:</strong></span></h3>
<blockquote>
<pre class="has" data-index="0" name="code"><code class="language-cs hljs language-csharp"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">using</span> UnityEngine;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">using</span> System.Collections;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Label</span> : <span class="hljs-title">MonoBehaviour</span> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">OnClick</span>()</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> {</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> UILabel lbl = <span class="hljs-keyword">this</span>.GetComponent<UILabel>();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">//获取鼠标点击位置出的超链接</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-built_in">string</span> url=lbl.GetUrlAtPosition(UICamera.lastHit.point);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="11"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-keyword">if</span>(!<span class="hljs-built_in">string</span>.IsNullOrEmpty(url))</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="12"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> <span class="hljs-comment">//打开超链接</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="13"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> Application.OpenURL(url);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="14"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> }</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" οnclick="hljs.copyCode(event)"></div></pre>
<p> </p>
</blockquote>
<p> </p>
<p> </p>
</div><div><div></div></div>
</div>
NGUI插件之Label
最新推荐文章于 2024-10-13 14:46:47 发布