Forum Archive

Create and Rotate Label

mcarrara3

Hello, how can I create and rotate a label of pi/2? I've already tried the GState() example, but when you input pi/2 the text disappears...

JonB

Can you post an example of what you tried?

mcarrara3

I think I figured it out by myself. Here's the code, in case someone needs it!

# coding: utf-8
import ui
from math import pi

# Preliminary step: create an empty UI and call it myview

# loading view
v = ui.load_view('myview')

# creating label
ylabel = ui.Label()
ylabel.text = 'Hello World'
ylabel.center = (v.width/2., v.height/2.)

#creating a transform object
rot = ui.Transform.rotation(-pi/2)

# applying the transform object to the label
ylabel.transform = rot

# adding the label to the view
v.add_subview(ylabel)

v.present()