unity ugui图片自适应文字内容大小

本文转摘自博客园: 倾城之叹
1、(UI提示框与文字) Unity Text组件需要与Image组件自适应

新建如图的UI物体
unity ugui图片自适应文字内容大小_第1张图片
unity ugui图片自适应文字内容大小_第2张图片
unity ugui图片自适应文字内容大小_第3张图片
如图为Image的RectTransform中设置Pivot(中心点),如果需要向上向左适应,则将中心点设置在Image的右下方,并添加Content Size Fitter 组件(放在父物体上,可以根据子物体的大小来控制父物体的大小),添加Horizontal Layout Group 组件,控制布局

Text就不要什么设置了。

下面贴出Content Size Fitter组件的描述里的一段话:
For example, when the pivot is in the center, the Content Size Fitter will expand the Rect Transform out equally in all directions. And when the pivot is in the upper left corner, the Content Size Fitter will expand the Rect Transform down and to the right.
大致意思好像是如果设置中心点(pivot )为中间,那么这个 Content Size Fitter 组件会想四周扩展自己来调整自适应大小,如果中心点设置为左上,那么就会向右下扩展自己来调整自适应大小。
我想这样就可以解释为什么锚点这样设置了。

你可能感兴趣的:(Unity3D)