我想这样做:Image
在我的故事板中,我放了这样的标签:Image
每个标签都是70Widht和20Height
标签名称为:
label1 (position x:20 y:161)
label2 (position x:50 y:161)
label3 (position x:80 y:161)
label4 (position x:110 y:161)
label5 (position x:140 y:161)
label6 (position x:170 y:161)
label7 (position x:200 y:161)
label8 (position x:230 y:161)
label9 (position x:260 y:161)
label10 (position x:290 y:161)
在我的ViewController.h中:
@property (strong, nonatomic) IBOutlet UILabel *label1;
@property (strong, nonatomic) IBOutlet UILabel *label2;
@property (strong, nonatomic) IBOutlet UILabel *label3;
@property (strong, nonatomic) IBOutlet UILabel *label4;
@property (strong, nonatomic) IBOutlet UILabel *label5;
@property (strong, nonatomic) IBOutlet UILabel *label6;
@property (strong, nonatomic) IBOutlet UILabel *label7;
@property (strong, nonatomic) IBOutlet UILabel *label8;
@property (strong, nonatomic) IBOutlet UILabel *label9;
@property (strong, nonatomic) IBOutlet UILabel *label10;
在ViewDidLoad方法的ViewController.m中:
[label1 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[label2 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[label3 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[label4 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[label5 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[label6 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[label7 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[label8 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[label9 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
[label10 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];
但是当我运行模拟器时出现了问题:Image
前五个标签没问题,但其他五个标签处于随机位置。
我该如何解决这个问题?
答案 0 :(得分:0)
在IB中,从包含所有标签的超级视图开始。将标签放在包含从上到下堆叠的超视图的标签中,左对齐...如果它们没有旋转,您将看到它们的预期效果。
设置包含超级视图的插座,并对其应用单个-M_PI/2
转换。
答案 1 :(得分:0)
使用此代码:
label1.transform = CGAffineTransformMakeRotation(DegreesToRadians(270));
等等。
也定义
定义DegreesToRadians(x)((x)* M_PI / 180.0)