UIRichText(富文本元素基类,它定义了所有富文本元素的基本公共属性)公有属性、方法
/**
* 富文本类型
*/
enum class Type
{
TEXT, // 文本
IMAGE, // 图片
CUSTOM, // 自定义内容
NEWLINE // ?
};
RichElementText(用于显示文本)
/**
* 创建RichElementText实例
* @param tag 标识
* @param color 字体色
* @param opacity 透明度
* @param text 文本内容
* @param fontName 字体
* @param fontSize 字体大小
* @return 创建RichElementText实例
*/
static RichElementText* create(int tag, const Color3B& color, GLubyte opacity, const std::string& text, const std::string& fontName, float fontSize);
RichElementImage(用于显示图片)
/**
* 创建RichElementImage实例
* @param tag 标识
* @param color 颜色
* @param opacity 透明度
* @param filePath 图片类型(Local、Plist)
* @return RichElementImage实例
*/
static RichElementImage* create(int tag, const Color3B& color, GLubyte opacity, const std::string& filePath);
RichElementCustomNode(用于显示自定义节点类型)
/**
* 创建一个RichElementCustomNode实例
*
* @param tag 标识
* @param color 颜色
* @param opacity 透明度
* @param customNode 自定义节点
* @return A RichElementCustomNode instance.
*/
static RichElementCustomNode* create(int tag, const Color3B& color, GLubyte opacity, Node* customNode);
RichElementNewLine(用于显示新元素?)
/**
* 创建一个RichElementNewLine实例
*
* @param tag 标识
* @param color 颜色
* @param opacity 透明度
* @return RichElementNewLine实例
*/
static RichElementNewLine* create(int tag, const Color3B& color, GLubyte opacity);
RichText(显示各种RichElements的容器)
/**
* 构造函数
* @return RichText实例
*/
static RichText* create();
/**
* 插入一个RichElement对象到指定索引位置
* @param element 继承于RichElement的对象
* @param index 索引
*/
void insertElement(RichElement* element, int index);
/**
* 在RichText的末尾添加一个RichElement
* @param element 继承于RichElement的对象
*/
void pushBackElement(RichElement* element);
/**
* 在给定的索引处移除RichElement
* @param index 索引
*/
void removeElement(int index);
/**
* 删除特定的RichElement
* @param element 继承于RichElement的对象
*/
void removeElement(RichElement* element);
/**
* 在每个RichElement之间设置垂直空间
* @param space 垂直方向间距值
*/
void setVerticalSpace(float space);
/**
* 重新排列RichText中的所有RichElement
* 通常在内部调用
*/
void formatText();
UIRichText 示例
// 富文本
var richText = new ccui.RichText();
richText.ignoreContentAdaptWithSize(true);
richText.setAnchorPoint(0, 0.5);
richText.setPosition(10, 20);
richText.setSize(340, 30);
var rewardNumber = "";
var rewardIcon = null;
switch (item.prize_type) {
case 1: rewardNumber = "张房卡"; rewardIcon = this.icon_roomcard_s; break;
case 2: rewardNumber = "元红包"; rewardIcon = this.icon_redpacket_s; break;
case 3: rewardNumber = "个幸运点"; rewardIcon = this.icon_dice_s; break;
}
var re1 = new ccui.RichElementText(1, cc.hexToColor("#9A510E"), 255, "玩家[" + (item.userNickName || "") + "]抽中", "STYuanti-SC-Regular", 21);
var re2 = new ccui.RichElementText(1, cc.hexToColor("#E43615"), 255, item.prize_num || "0", "STYuanti-SC-Regular", 25);
var re3 = new ccui.RichElementText(1, cc.hexToColor("#9A510E"), 255, rewardNumber, "STYuanti-SC-Regular", 21);
richText.pushBackElement(re1);
richText.pushBackElement(re2);
richText.pushBackElement(re3);
this.addChild(richText);