如何在NSString中使用CGAffineTransformMakeRotation

时间:2012-08-05 08:40:21

标签: iphone objective-c

我想为NSString使用CGAffineTransformMakeRotation,我该怎么做?它使用标签,我只需要我的函数字符串。

2 个答案:

答案 0 :(得分:3)

CGAffineTransformMakeRotation用于设置transform的{​​{1}}属性,UIView不是NSString因此无法转换,它没有概念轮换

您需要在显示时使用UIView

执行此操作

一个例子:

UILabel

答案 1 :(得分:0)

您可以像下面的代码一样旋转文字标签:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib
    label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    label.text = @"fof fof fof";
    [self.view addSubview:label];
}

- (IBAction)rotate:(id)sender {
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(endAnimation)];
    CGAffineTransform rotate = CGAffineTransformMakeRotation(90.0f * (M_PI / 180.0f));
    label.transform = rotate;

    [UIView commitAnimations];  
}