当前位置:网站首页>Unity3d button adapts the size according to the text content
Unity3d button adapts the size according to the text content
2022-06-27 20:55:00 【Cai Cai any】
The effect is shown in the figure

Realization :
1.Text add to ContentSizeFitter Components , As shown in the figure :

2.Button Add a script TextAutoSize
public class TextAutoSize : MonoBehaviour
{
public RectTransform textRect;//Text Components
// Start is called before the first frame update
void Start()
{
LayoutRebuilder.ForceRebuildLayoutImmediate(textRect);
this.GetComponent<RectTransform>().sizeDelta = new Vector2(textRect.sizeDelta.x + 30, 40);
}
// Update is called once per frame
void Update()
{
}
}边栏推荐
- 开启生态新姿势 | 使用 WrodPress 远程附件存储到 COS
- Pycharm common functions - breakpoint debugging
- Redis 大 key 问题处理总结
- 安全才是硬道理,沃尔沃XC40 RECHARGE
- Wechat IOS version 8.0.24 update release cache subdivision cleaning Online
- Database log
- Oracle architecture summary
- [array]bm99 clockwise rotation matrix - simple
- Question brushing notes - tree (easy) - updating
- UOS prompts for password to unlock your login key ring solution
猜你喜欢
一段时间没用思源,升级到最新的 24 版后反复显示数据加密问题

BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比

谈谈我写作生涯的画图技巧

BAIC makes a brand new pickup truck, which is safe and comfortable

北汽制造全新皮卡曝光,安全、舒适一个不落
![[STL programming] [common competition] [Part 2]](/img/67/2a2d787680c0984f6c294a9ec3355b.png)
[STL programming] [common competition] [Part 2]

BTC和ETH重新夺回失地!引领市场复苏?加密将步入“冰河时代”!

NVIDIA three piece environment configuration

CSDN 技能树使用体验与产品分析(1)

Linux system Oracle 19C OEM monitoring management
随机推荐
Binary tree related problems 2
北汽制造全新皮卡曝光,安全、舒适一个不落
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
Postman Chinese tutorial (postman Chinese version)
分享|智慧环保-生态文明信息化解决方案(附PDF)
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
"Good voice" has been singing for 10 years. How can the Chinese language in the starry sky sing well in HKEx?
No wonder people chose apifox instead of postman
元宇宙虚拟数字人离我们更近了|华锐互动
爱数课实验 | 第七期-基于随机森林的金融危机分析
Installation and configuration of grayog new generation log collection early warning system
Backtracking related issues
1030 Travel Plan
UOS prompts for password to unlock your login key ring solution
SQL报了一个不常见的错误,让新来的实习生懵了
What is a low code development platform? Why is it so hot now?
DBeaver恢复和备份数据库的方式
Explore gaussdb and listen to what customers and partners say
I haven't thought about the source for some time. After upgrading to the latest version 24, the data encryption problem is repeatedly displayed
一段时间没用思源,升级到最新的 24 版后反复显示数据加密问题