Hi,
I need help placing text inside a scroll view.
The text has been parsed from a website in the form of JSON.
Here is my code:
[lua]local storyboard = require(“storyboard”)
local json = require (“json”)
local widget = require(“widget”)
local scene = storyboard.newScene()
function scene:createScene(event)
local group = self.view
local background = display.newRect(0, 0, display.contentWidth, display.contentHeight+30)
background:setFillColor(255)
local titleBox = display.newRect(0,100,display.contentWidth,75)
titleBox:setReferencePoint(display.CenterReferencePoint)
titleBox:setFillColor(100)
local titleText = display.newText(event.params.entry[‘title’], display.contentWidth/2.5, 115, native.systemFont, 24 )
titleText.x = display.contentWidth/2
local authorText = display.newText(event.params.entry[‘author’], display.contentWidth/2.5, 145, native.systemFont, 20 )
authorText.x = display.contentWidth/2
local content = event.params.entry[‘content’]
content = content:gsub( “<.->”, “”)
local articleText = display.newText(content, 10, 180, display.contentWidth*0.9, 0, native.systemFont, 24)
articleText:setTextColor(30)
local backButton = display.newImage(“backButton.png”, -10, 25)
local function backButtonTapped(event)
storyboard.removeScene(“view2”)
storyboard.gotoScene(“view1”)
end
backButton:addEventListener(“tap”, backButtonTapped)
local function scrollListener(event)
local phase = event.phase
if (phase == “began”) then print(“Scroll view was touched”)
elseif (phase == “moved”) then print(“Scroll view was moved”)
elseif (hase == “ended”) then print(“Scroll view was released”)
end
if (event.limitReached) then
if (event.direction == “up”) then print(“Reached top limit”)
elseif (event.direction == “down”) then print(“Reached bottom limit”)
end
end
return true
end
local scrollView = widget.newScrollView
{
top = 180,
left = 0,
width = display.contentWidth,
height = display.contentHeight,
scrollWidth = display.contentWidth,
horizontalScrollDisabled = true
}
listener = scrollListener
group:insert(background)
group:insert(titleBox)
group:insert(articleText)
group:insert(titleText)
group:insert(authorText)
group:insert(scrollView)
end[/lua]
Thanks