RichTextHelp_launcher.lua 1.0 KB

1234567891011121314151617181920212223242526
  1. local RichTextHelp = class('RichTextHelp')
  2. function RichTextHelp:CreateRichTextWithXML(str, width, defaultSize, defaultColor, callback)
  3. -- defaultColor = "#FFFFFF" 颜色采用这种格式
  4. -- callback 将 a href = "" href中的参数传回
  5. if str == nil then
  6. return self:CreateRichTextWithXML("空富文本")
  7. end
  8. width = width or 100
  9. defaultSize = defaultSize or 100
  10. defaultColor = defaultColor or "#FFFFFF"
  11. local richText = ccui.RichText:createWithXML(str, { KEY_FONT_SIZE = defaultSize, KEY_FONT_FACE = "fonts/font.ttf", KEY_FONT_COLOR_STRING = defaultColor, KEY_ANCHOR_FONT_COLOR_STRING = "#FFFFFF", KEY_ANCHOR_TEXT_LINE = "VALUE_TEXT_LINE_UNDER", KEY_ANCHOR_TEXT_OUTLINE_SIZE = 1 })
  12. if not richText then
  13. print("富文本错误:", str)
  14. return self:CreateRichTextWithXML("富文本错误")
  15. end
  16. richText:ignoreContentAdaptWithSize(false)
  17. richText:setContentSize(width, 0)
  18. richText:setTouchEnabled(false)
  19. return richText
  20. end
  21. return RichTextHelp