UGUI ContentSizeFitter之Button根据Text自适应
2017-06-22 17:59
393 查看
环境
Unity3D 5.3.6f1练习地址:https://github.com/zhaoqingqing/UGUIDemo 布局放在Layout文件夹
文档:https://docs.unity3d.com/Manual/script-ContentSizeFitter.html
button根据Text自适应
效果如下:Button的长度会根据Text的长度自动变化Button的设置如下:
1、添加HorizontalLayoutGroup,并设置Padding,就是左右两边的空白,因为我们是想让Button的长度(水平方向)做变化,所以我们添加Horizontal组件。
2、添加 ContentSizeFitter,这个组件的Horizontal Fit(水平适配)设置了PreferredSize(优先尺寸),当Text的PreferrdWidth发生改变之后,它就会改变Button的长度。
ContentSizeFitter
ContentSizeFitter的描述:The size is determined by the minimum or preferred sizes provided by layout element components on the Game Object. Such layout elements can be Image or Text components, layout groups, or a Layout Element component.需要和Layout系列的组件结合使用。
相关文章推荐
- 重写hierarchy面板,实现创建Text自动添加content size fitter组件
- textview的contentsize.height不能准确判断高度,尤其是在文本中同时包含中英文时,如此便不能高度自适应,求解如何textview自适应
- Unity ugui button自适应text大小
- UGUI使用小技巧 Content Size Fitter(一)
- unity UGUI text font size对性能影响较大
- button根据文字内容大小自适应
- Android ImageView设置长度高度为wrap_content时高度根据图片比例自适应
- Android ImageView设置长度高度为wrap_content时高度根据图片比例自适应
- 08-21 RadioGroup,RadioButton autoLink属性 TextView中ellipsize属性 TextView的属性
- Android根据所设置的textSize获取字体高度和设置行高
- UGUI Text大小自适应
- iOS UITextView 根据输入text自适应高度
- Unity3D ScrollRect+ContentSizeFitter+GridLayoutGroup实现无限滚动(一)
- 08-21 RadioGroup,RadioButton autoLink属性 TextView中ellipsize属性 TextView的属性
- Android 让GridView的高度为Wrap_content根据内容自适应高度
- unity, ContentSizeFitter立即生效
- Unity UI(九):UI布局之Layout Element、Content Size Fitter和Aspect Ratio Fitter
- 关于textView根据输入内容自适应高度
- iOS UITextView 根据输入text自适应高度
- 【UGUI】UGUI 文字背景根据文字大小自适应