I used the following code to rotate the label text
mylabel.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
this will work. But it will rotate UILabel
in Center .
let say my Top left corner of UILabel
is (10,10) when i rotate it its Top left corner should not be change(Just like radius or circle).
How i can rotate it with respect to Top Left corner ?.
please help me
Edit:
here is code
var transA = CGAffineTransformMakeTranslation(mylabel.frame.size.width/2,mylabel.frame.size.height/2);
var rotation = CGAffineTransformMakeRotation(CGFloat(M_PI_4));
var transB = CGAffineTransformMakeTranslation(-mylabel.frame.size.width/2,-mylabel.frame.size.height/2);
mylabel.transform = CGAffineTransformConcat(CGAffineTransformConcat(transA,rotation),transB);
var transform = transA
mylabel.transform = CGAffineTransformConcat(mylabel.transform, transform)
EDIT Question : how to make my Label look like a radius of Circle. i.e. i can rotate it 360 with respect to origin?
There are two things you can do about this.
A)
You can change the anchor point of the Label:
Now you can rotate around this point. This will change the anchor point for ALL transforms!
B)
You could do something like this:
This won't change your anchor point and therefore not impact other transforms!
(If the rotation is wrong, you may have to change
transA
againsttransB
)UPDATE
If you want to 'keep' rotation (as asked in the comments), you can just do this:
This way you just say 'whereever' I was before - rotate 90 (or 45) degrees more
UPDATE 2
Your code should look like this: