4

i'm creating an iphone app.in that application i want to angle the label according to the attached screen shot. enter image description here (see the $ 120 lable)

The red color image is in the background and i want to angle the uilabel top of it

I have used the transformmethod to rotate . But it does not properly angle it. label shrinks

testLabel.transform = CGAffineTransformMakeRotation(30 * M_PI / 180.0);
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
Mr.G
  • 1,275
  • 1
  • 18
  • 48
  • What do you mean it shrinks? Can you post the code you used. Also, are you using AutoLayout? – Fogmeister Jul 08 '13 at 09:05
  • no i dont use the autolayout . testLabel.transform = CGAffineTransformMakeRotation(30 * M_PI / 180.0); . also this angles from different side. which means the angle shout start from left . not right – Mr.G Jul 08 '13 at 09:07
  • 1
    Can you post a screenshot of what is happening when you use that code. Also, the more code you can provide the easier it is for us to help. (P.S. put code into your question, not a comment). – Fogmeister Jul 08 '13 at 09:08
  • 1
    it shouldn't shrink but you can make testLabel.transform = CGAffineTransformMakeRotation(-30 * M_PI / 180.0); to show from the left. – soryngod Jul 08 '13 at 09:10
  • @soryngod do you know what "start from left" means? Not sure what is meant by that. – Fogmeister Jul 08 '13 at 09:11
  • @Fogmeister the initial code was showing the label angled from the right so i guessed he wanted to angle it from the left. Anyway , this looks easy to do . – soryngod Jul 08 '13 at 09:15
  • "From the right" does that mean clockwise and anti-clockwise? Or do you mean the point (centre) of rotation? – Fogmeister Jul 08 '13 at 09:16

5 Answers5

5

Try something like this :

label.transform = CGAffineTransformMakeRotation(M_PI / 4); //  45 degree rotation 
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
5

Try this..

#define DEGREES_TO_RADIANS(angle) (angle / 180.0 * M_PI)


CGAffineTransform transform = 
    CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(0.-7));
    lbl.transform = transform;
    lbl.text=name;
Lokesh Chowdary
  • 816
  • 5
  • 22
3

Your label shrinks due to setting wrong frame. You should place your label into the UIView and rotate this view instead of label. And also check your UIView have no any autoresizing anchors enabled.

Andrei Chevozerov
  • 1,029
  • 1
  • 10
  • 24
2

Use transform property of UILabel

such like

lblComingSoon.transform = CGAffineTransformMakeRotation(M_PI_2*2.5);// your can set angle as you need.

Alos read this official documantaion.
And

For more information this Question is related to yours Question => Objective C: How can you rotate text for UIButton and UILabel?

Community
  • 1
  • 1
iPatel
  • 46,010
  • 16
  • 115
  • 137
0

use this code:

label.transform = CGAffineTransformMakeRotation(2*M_PI / 3); 
Ravee10
  • 355
  • 1
  • 3
  • 13