2016-09-11 17 views
1

Corona SDK의 한 줄 안의 단어 틀을 정확히 알 수있는 방법은 무엇입니까? 즉, 특정 단어 위에 rect를 추가하고 싶습니다. 대신 webview를 사용하고 mark 태그를 사용했지만 iOS에서 webview가 계속 깜박 거리면 webview 솔루션이 취소됩니다.corona sdk에서 단어 주위에 rect를 추가하는 방법은 무엇입니까?

highlight

나는이 단어에 수동으로 구형 영역을 추가 한

,하지만 나는 단어를 지정하고 다음 단어로 RECT를 이동처럼 내가는 RECT 그것을 강조 있도록 프레임 알고 가장 좋은 방법은 ? 내가 사용하는 글꼴은 Arial이고, 고정 폭 글꼴이 아닙니다.

  local myRect = display.newRect(20,165,32,12.5) 
      myRect.alpha = 0.5 
      myRect:setFillColor(1,1,0) 
      myRect.anchorX = 0 

      local myString = "Word is highlighted" 
      local line = display.newText(myString, 0,165, "Arial", 12.5) 
      line.anchorX = 0 
      line.x = 20 

감사합니다.

+0

텍스트 색상을 구별 할 수 없습니까? – Amir

+0

단어 색상을 변경하는 방법을 알고 있다면 답변을 추가하십시오. – DeyaEldeen

+0

전체 텍스트는 단지 개체이며 전체 텍스트를 제어 할 수 있습니다. 내가 아는 유일한 방법은 각 단어를 대상으로 분리하여 원하는대로 색칠하는 것입니다. – Amir

답변

1

만약 내가 당신이라면 나는 그것에 대한 추가 기능을 작성합니다. 뭔가 같이 :

function highlightedText(pre, high, post, x, y, font, size) 
    local text = display.newText("", x, y, font, size) 
    local dx, rectangle = 0 
    if pre then 
     local t = display.newText(pre, 0, 0, font, size) 
     text.text = pre 
     dx = t.width 
     -- We need to add line below according to Corona Docs 
     text.anchorX = 0 text.x = x text.y = y 
     t:removeSelf() 
    end 
    if high then 
     local t = display.newText(high, 0, 0, font, size) 
     rectangle = display.newRect(x+dx, y, t.width, t.height) 
     rectangle:toBack() 
     text.text = text.text .. high 
     -- We need to add line below according to Corona Docs 
     text.anchorX = 0 text.x = x text.y = y 
     t:removeSelf() 
    end 
    if post then 
     text.text = text.text .. post 
     -- We need to add line below according to Corona Docs 
     text.anchorX = 0 text.x = x text.y = y 
    end 
    return text, rectangle, dx -- `dx` passed in case of moving whole text along with rectangle 
end 

local text, rect, _ = highlightedText("The", "word", "is highlighted.", 10, 10, "Arial", 12.5) 

rect.alpha = 0.5 
rect:setFillColor(1,1,0) 
rect.strokeWidth = 3 

text:setFillColor(1,1,1) 

나는 코로나에 전문가는 아니지만 그러나 이것은 한 줄 정적 텍스트가 잘 작동합니다.

+0

이것은 매우 정확하지는 않지만, 제가 발견 한 해결책과 비슷합니다, 감사합니다. – DeyaEldeen

0

시도해보십시오.

local player2 = display.newText("test221234567890", 210, 210) 
player2:setFillColor(0.6, 0.4, 0.8) 

local myRectangle = display.newRect(player2.x, player2.y, player2.width, player2.height) 
myRectangle.strokeWidth = 3 
myRectangle:setFillColor(0.5) 
myRectangle:toBack() 
+0

전 텍스트가 아닌 전체 텍스트에서 단어를 강조하고 싶습니다. – DeyaEldeen

관련 문제