当前位置:网站首页>Unity3D Button根据文本内容自适应大小
Unity3D Button根据文本内容自适应大小
2022-06-27 18:34:00 【菜菜ANY】
效果如图所示

实现:
1.Text添加ContentSizeFitter组件,如图所示:

2.Button添加脚本TextAutoSize
public class TextAutoSize : MonoBehaviour
{
public RectTransform textRect;//Text组件
// 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()
{
}
}边栏推荐
- 探秘GaussDB,听听客户和伙伴怎么说
- [login interface]
- 润迈德医疗开启招股:未有基石投资者参与,亏损金额翻倍增长
- 最佳实践:优化Postgres查询性能(下)
- Csdn Skills Tree use Experience and Product Analysis (1)
- UOS提示输入密码以解锁您的登陆密钥环解决办法
- Database lock problem
- Character interception triplets of data warehouse: substrb, substr, substring
- 云原生安全指南: 从零开始学 Kubernetes 攻防
- What is a low code development platform? Why is it so hot now?
猜你喜欢

MongoDB简介及典型应用场景

Postman 汉化教程(Postman中文版)

安装NFS服务

It took me 6 months to complete the excellent graduation project of undergraduate course. What have I done?

pfSense Plus22.01中文定制版发布

【STL编程】【竞赛常用】【part 3】

Redis持久化

基于 TensorRT 的模型推理加速

SQL audit platform permission module introduction and account creation tutorial

北汽制造全新皮卡曝光,安全、舒适一个不落
随机推荐
Database transactions
数据库事务
SQL审核平台权限模块介绍和账号创建教程
It took me 6 months to complete the excellent graduation project of undergraduate course. What have I done?
Enumeration and control flow operation in rust
Explore gaussdb and listen to what customers and partners say
Batch insert data using MySQL bulkloader
Record a failure caused by a custom redis distributed lock
Openharmony hisysevent dotting and calling practice of # Summer Challenge (L2)
Data intelligence enters the "deep water area", and data governance is the key
SQL报了一个不常见的错误,让新来的实习生懵了
最佳实践:优化Postgres查询性能(下)
ABAP-CL_ OBJECT_ Collection tool class
Massive data attended the Lanzhou opengauss meetup (ECOLOGICAL NATIONAL trip) activity, enabling users to upgrade their applications with enterprise level databases
Character interception triplets of data warehouse: substrb, substr, substring
数据库引擎
CSDN skill tree experience and product analysis (1)
Recommended practice sharing of Zhilian recruitment based on Nebula graph
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
Question brushing record: easy array (continuously updated)