当前位置:网站首页>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()
{
}
}边栏推荐
- Massive data attended the Lanzhou opengauss meetup (ECOLOGICAL NATIONAL trip) activity, enabling users to upgrade their applications with enterprise level databases
- 数仓的字符截取三胞胎:substrb、substr、substring
- Bit. Store: long bear market, stable stacking products may become the main theme
- [array]bm99 clockwise rotation matrix - simple
- Character interception triplets of data warehouse: substrb, substr, substring
- 最佳实践:优化Postgres查询性能(下)
- Backtracking related issues
- What is a stack?
- 低代码开发平台是什么?为什么现在那么火?
- Leetcode 989. Integer addition in array form (simple)
猜你喜欢

muduo
I haven't thought about the source for some time. After upgrading to the latest version 24, the data encryption problem is repeatedly displayed
![[bug] Lenovo Xiaoxin has a problem. Your pin is unavailable.](/img/2a/da8e998cb4e89d655f3c4116316925.png)
[bug] Lenovo Xiaoxin has a problem. Your pin is unavailable.

Massive data attended the Lanzhou opengauss meetup (ECOLOGICAL NATIONAL trip) activity, enabling users to upgrade their applications with enterprise level databases

数据库锁问题

可观测,才可靠:云上自动化运维CloudOps系列沙龙 第一弹

基于 TensorRT 的模型推理加速

OpenSSL client programming: SSL session failure caused by an obscure function

Oracle architecture summary
![[STL programming] [common competition] [Part 1]](/img/ce/4d489e62d6c8d16134262b65d4b0d9.png)
[STL programming] [common competition] [Part 1]
随机推荐
Accumulating power in the middle stage, UFIDA IUAP builds a new base for digital intelligence of social enterprises
OpenSSL client programming: SSL session failure caused by an obscure function
【精品必读】Linux系统Oracle数据库趣解子查询
主键选择选择自增还是序列?
NVIDIA三件套环境配置
Univision hyperinsight: Nuggets' $16.494 billion "gold hoe" in the observable market?
Database optimization
What is a stack?
linux系统笑着玩Oracle数据库多表查询-连接查询
Redis data structure
Web APls 阶段——第十四节——本地存储
Hash table - Review
Massive data attended the Lanzhou opengauss meetup (ECOLOGICAL NATIONAL trip) activity, enabling users to upgrade their applications with enterprise level databases
SQL报了一个不常见的错误,让新来的实习生懵了
Batch insert data using MySQL bulkloader
Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison
Record a failure caused by a custom redis distributed lock
A distribution fission activity is more than just a circle of friends
Mass lucky hash game system development - conflict resolution (code analysis)
低代码开发平台是什么?为什么现在那么火?