我正在尝试将 View 中的标签旋转 90 度。我已经尝试了以下两种方法来做到这一点,标签就从屏幕上消失了。我三次检查了属性是否正确附加。有什么想法吗?
尝试一:
// rotating labels 90 degrees
self.labelCloseScroll.transform = CGAffineTransformMakeRotation (3.14/2);
尝试二:
CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);
rotate = CGAffineTransformScale(rotate, 1, 1);
[self.labelCloseScroll setTransform:rotate];
最佳答案
我不是 100% 确定它是否有效,但您为什么不使用 M_PI_2
。这只是简单的想法,您假设 Value of Pi
为 3.14
但确切的值为 3.14159...
我是这样做的,效果很好:
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 50, 70)];
lbl.text = @"New";
lbl.backgroundColor = [UIColor clearColor];
lbl.textColor = [UIColor whiteColor];
lbl.highlightedTextColor = [UIColor blackColor];
lbl.font = [UIFont systemFontOfSize:12];
lbl.transform = CGAffineTransformMakeRotation(M_PI_2);
[self.view addSubview:lbl];
您还可以查看这些问题的答案:
How to Render a rotated UIlabel
Rotating UILabel at its center
希望对您有所帮助。
关于iphone - iOS - 尝试旋转文本标签并且标签消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14291600/