zoukankan      html  css  js  c++  java
  • ugui在运行时改变RectTransform的大小

    http://blog.csdn.net/BeiFuDeNvWang/article/details/50838266

    在代码中动态改变RectTransform大小的方法如下所示:

    1:直接对sizeDelta属性进行赋值,其中X和Y可以对应理解成width和height。sizeDelta的具体含义:若achors是一个点的话则代表宽高,否则为到锚点的距离

    var rt = gameObject.GetComponent<RectTransform>();
    rt.sizeDelta = new Vector2(100, 30);

    2:使用SetSizeWithCurrentAnchors函数来进行设定,其中Horizontal和Vertical分别对应宽和高。此函数受当前锚点和中心点的影响。

    var rt = gameObject.GetComponent<RectTransform>();
    rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100);
    rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 30);

    3:使用SetInsetAndSizeFromParentEdge函数来进行设定。此函数不受锚点和中心的影响,其中第一个参数代表对齐方式,第二个参数为距离边界的距离,第三个参数为宽度。

    var rt = gameObject.GetComponent<RectTransform>();
    rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, 100);
    rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0, 30);


    在确定使用绝对位置的时候,推荐使用第三种方法。 
    参考文章:http://www.manew.com/thread-41633-1-1.html


  • 相关阅读:
    Python容器篇 4 -- 字典
    Python容器篇 3 -- 元组
    Python容器篇 2 -- 列表
    Python容器篇 1 -- 字符串
    Python中的关键字
    SQLI-LABS靶场环境搭建详细流程
    Qt QLineEdit 改变text内容的大小
    linux下QT连接mysql找不到驱动
    apt(rpm) Mysql安装
    const 成员函数
  • 原文地址:https://www.cnblogs.com/nafio/p/9137337.html
Copyright © 2011-2022 走看看