Formatting text w/in a string? Is there a way?

Hi all,
I’m a little afraid of the answer, but does anyone know of a way to format text within a string? To have individual words appear as bold, or in a different color, for example? Taking this even further, is there a way to make just one word of a string into an object that could receive touch events?

My first guess is that this would require displaying different strings, each containing whatever formatting is required. That then presents the problem of how do you force them to appear as a seamless paragraph of text?

Any ideas would be most appreciated!!

Thanks, Chris [import]uid: 97836 topic_id: 31918 reply_id: 331918[/import]

Corona doesn’t support inline character formatting like that. You could however use a native.newWebView() and load a little HTML snippet into a box on the page. That would give you full CSS/HTML control over the text in that box. You could even use anchor tags and have the webView’s listener intercept them and direct your app to do things on touch.

[import]uid: 19626 topic_id: 31918 reply_id: 127317[/import]

Corona doesn’t support inline character formatting like that. You could however use a native.newWebView() and load a little HTML snippet into a box on the page. That would give you full CSS/HTML control over the text in that box. You could even use anchor tags and have the webView’s listener intercept them and direct your app to do things on touch.

[import]uid: 19626 topic_id: 31918 reply_id: 127317[/import]

@robmiracle,

Thanks so much for the reply. It sounds very complicated - any chance you’d be inclined to give me a little example?

Many thanks!

Chris [import]uid: 97836 topic_id: 31918 reply_id: 127490[/import]

Given my current work load, probably not in a timely enough manner.

Take this snippet and drop it into your folder with your main.lua:

  
[html]  
  
<style><br>.brown { text-color:#4B0; }<br></style>

How **Now** Brown _Cow!_

  

[Tap Me!](corona:click-me)

  
  
[/html]  

save that to a file called browncow.html

Now do something like this in your code:

  
local function webListener( event )  
 if event.url == "corona:click-me" then  
 -- do whatever you want to do when that text is typed here!  
 end  
 return true  
end  
  
local webView = native.newWebView( 0, 0, 320, 100 )  
webView:request( "browncow.html", system.ResourceDirectory --you might need to add ,webListener here.....)  
webView:addEventListener( "urlRequest", webListener )  
  

I don’t have time to test it, but in general that’s the primace.

http://docs.coronalabs.com/api/library/native/newWebView.html [import]uid: 19626 topic_id: 31918 reply_id: 127500[/import]

Thanks so much!! [import]uid: 97836 topic_id: 31918 reply_id: 127519[/import]

@robmiracle,

Thanks so much for the reply. It sounds very complicated - any chance you’d be inclined to give me a little example?

Many thanks!

Chris [import]uid: 97836 topic_id: 31918 reply_id: 127490[/import]

Given my current work load, probably not in a timely enough manner.

Take this snippet and drop it into your folder with your main.lua:

  
[html]  
  
<style><br>.brown { text-color:#4B0; }<br></style>

How **Now** Brown _Cow!_

  

[Tap Me!](corona:click-me)

  
  
[/html]  

save that to a file called browncow.html

Now do something like this in your code:

  
local function webListener( event )  
 if event.url == "corona:click-me" then  
 -- do whatever you want to do when that text is typed here!  
 end  
 return true  
end  
  
local webView = native.newWebView( 0, 0, 320, 100 )  
webView:request( "browncow.html", system.ResourceDirectory --you might need to add ,webListener here.....)  
webView:addEventListener( "urlRequest", webListener )  
  

I don’t have time to test it, but in general that’s the primace.

http://docs.coronalabs.com/api/library/native/newWebView.html [import]uid: 19626 topic_id: 31918 reply_id: 127500[/import]

Thanks so much!! [import]uid: 97836 topic_id: 31918 reply_id: 127519[/import]