How to angle a uilabel in ios [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-12-12 11:33:58

问题


i'm creating an iphone app.in that application i want to angle the label according to the attached screen shot.

(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);

回答1:


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.




回答2:


Try something like this :

label.transform = CGAffineTransformMakeRotation(M_PI / 4); //  45 degree rotation 



回答3:


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;



回答4:


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?




回答5:


use this code:

label.transform = CGAffineTransformMakeRotation(2*M_PI / 3); 


来源:https://stackoverflow.com/questions/17522666/how-to-angle-a-uilabel-in-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!