NSStringにCGAffineTransformMakeRotationを使用したいのですが、どうすればよいですか?ラベルで動作し、関数には文字列のみが必要です。
2 に答える
3
CGAffineTransformMakeRotation
transform
のプロパティを設定するために使用されますがUIView
、変換できNSString
ないため、回転の概念はありません。UIView
表示時にこれを行う必要がありますUILabel
例:
NSString *myString = @"whatever";
CGAffineTransform stringTransform = CGAffineTransformMakeRotation(M_PI / 2.0f);
UILabel *stringLabel = [[UILabel alloc] initWithFrame:labelFrame];
stringLabel.transform = stringTransform;
stringLabel.text = myString;
[self.view addSubview:stringLabel];
于 2012-08-05T08:49:23.267 に答える
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];
}
于 2012-08-05T09:57:30.430 に答える