xcode - How do I make the text of one label node take up 2 lines? -
i have text below long fit on screen when runs. how can make 2 lines rather one?
mylabel.text = "the weather today going partly cloudy chance of rain"
you can create own method display multi line text follow:
import spritekit class gamescene: skscene { override func didmovetoview(view: skview) { displaymultilinetextat(cgrectgetmidx(self.frame) - 100, y: cgrectgetmidy(self.frame) + 50, align: sklabelhorizontalalignmentmode.left, lineheight: 20.0, text: "welcome stackoverflow!\nthe weather today going to\nbe partly cloudy chance\nof rain.") } func displaymultilinetextat(x: cgfloat, y: cgfloat, align: sklabelhorizontalalignmentmode, lineheight: cgfloat, text: string) { let textnode = sknode() textnode.position = cgpointmake(x, y) var lineat: cgfloat = 0 line in text.componentsseparatedbystring("\n") { let labelnode = sklabelnode(fontnamed: "arial") labelnode.fontsize = 14 labelnode.horizontalalignmentmode = align labelnode.fontcolor = skcolor(hue: 1, saturation: 1, brightness: 1, alpha: 1) labelnode.position = cgpointmake(0, lineat) labelnode.text = line textnode.addchild(labelnode) lineat -= lineheight } scene!.addchild(textnode) } override func touchesbegan(touches: set<nsobject>, withevent event: uievent) { /* called when touch begins */ } override func update(currenttime: cftimeinterval) { /* called before each frame rendered */ } }
Comments
Post a Comment