UGUI 如何激活InputField并使脱字符号放到最后一个字符的位置

111 篇文章 3 订阅


 public InputField fff;

        // Use this for initialization
        void Start () {
        
        }
        
    public void test()
    {
        fff.selectionAnchorPosition = 0;
        fff.selectionFocusPosition = 100;
        fff.Select ();

是这个意思吧,,,,,,,,


在网上找到了答案:http://answers.unity3d.com/quest ... -an-inputfield.html
MoveTextEnd 可以让caret移动到最后,但是必须在此帧结束的时候,或者下一帧里才可以
我试验了下,做了个InputField的封装,可以实现你要的功能:

[AppleScript]  纯文本查看  复制代码
?
 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;
 
public class InputFieldWrapper : InputField {
 
     public override void OnSelect ( BaseEventData eventData ) {
         base.OnSelect ( eventData ) ;
         MoveTextEnd ( false ) ;
     }
 
     IEnumerator MoveTextEnd_NextFrame ( ) {
         yield return 0 ; / / Skip the first frame in which this is called.
         MoveTextEnd ( false ) ; / / Do this during the next frame.
     }
}

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
 
public class NewBehaviourScript : MonoBehaviour, ISelectHandler
{
     void ISelectHandler.OnSelect(BaseEventData eventData)
     {
         StartCoroutine(MoveTextEnd());
     }
 
     IEnumerator MoveTextEnd()
     {
         yield return null ;
         GetComponent<InputField>().MoveTextEnd( false );
     }
}


将这个脚本挂在inputfiled上就可以了



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值