UGUI中的文本添加链接下划线并跳转
来源:互联网 发布:淘宝买家举证 编辑:程序博客网 时间:2024/06/05 04:36
哈哈,想了很久,试了好几种方法,最后还是自己写一下
先看代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BtnTest : MonoBehaviour {
public Button btnselect;//不用在意这是测试的委托代码
public Text linkText;
void Awake()
{
linkText = GameObject.Find("Canvas").transform.Find("Text").GetComponent<Text>();
}
void Start()
{
CreateLink(linkText);
//给按钮绑定事件
ButtonEvent.Get(btnselect.transform).clickObj += selectOnClick;
// ButtonEvent.Get(textlint.transform).clickObj += onclick;
}
void selectOnClick()
{
Debug.Log("Test is Sucess");
}
public void onclick()
{
Application.OpenURL("www.baidu.com");
}
//创建下划线
public void CreateLink(Text text)
{
if (text == null)
return;
//克隆Text,获得相同的属性
Text underline = Instantiate(text) as Text;
underline.name = "Underline";
underline.transform.SetParent(text.transform);
RectTransform rt = underline.rectTransform;
//设置下划线坐标和位置
rt.anchoredPosition3D = Vector3.zero;
rt.offsetMax = Vector2.zero;
rt.offsetMin = Vector2.zero;
rt.anchorMax = Vector2.one;
rt.anchorMin = Vector2.zero;
underline.text = "_";
float perlineWidth = underline.preferredWidth; //单个下划线宽度
Debug.Log(perlineWidth);
float width = text.preferredWidth;
int lineCount = (int)Mathf.Round(width / perlineWidth);
for (int i = 1; i < lineCount; i++)
{
underline.text += "_";
}
}
}
不足之处请大家多多指教
- UGUI中的文本添加链接下划线并跳转
- UGUI 文本下划线实现
- UGUI 文本下划线实现
- CSS3 简单的链接文本自定义下划线
- Android 对text文本内容添加下划线
- 用CSS处理链接中的下划线
- Android 中为 TextView 的文本添加下划线
- UILabel 添加下划线,改变字体颜色,NSMutableAttributedString实现富文本
- Android:TextView中的文本链接之--点击链接跳转总结(2种方法+2个实例应用)
- IOS中给号码添加下划线,并拨号
- 给TextView中的部分文本添加链接的两种方式
- 提取EXCEL文本链接中的链接地址
- 安卓TextView中的文本加上横线或者下划线
- JS中添加链接跳转页面
- 即时通讯中,聊天信息如果有链接则设置下划线,并可点击进入相应链接
- 实现TextView文本下划线
- 向动态链接库中添加类和资源-并访问动态链接库中的类和资源
- UGUI富文本
- 时间戳工具类
- 深度学习基于TF破解验证码
- selenium+python测试全部用例
- ubuntu 16.04 配置国内快速软件源
- mongodb常用命令
- UGUI中的文本添加链接下划线并跳转
- python Threading线程关键点
- Reactor server 服务器模式的初步了解
- hibernate中@column自定义字段名无效错误解决
- eslint
- Navi.Soft31.产品.登录器(永久免费)
- JS——编码,解码
- Ubuntu16+GTX1050Ti配置tensorflow
- 深度解读 Tomcat 中的 NIO 模型