how to rotate uibutton like this in iphone sdk
10,308
Solution 1
If you have an IBOutlet Object.
theButton.transform = CGAffineTransformMakeRotation(M_PI / -4);
If you want to create run time button on view.
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(100, 100, 200, 44)];
btn.transform=CGAffineTransformMakeRotation(M_PI / -4);
[btn setTitle:@"RakeshBhatt" forState:UIControlStateNormal];
[self.view addSubview:btn];
}
Solution 2
theButton.transform = CGAffineTransformMakeRotation(-M_PI / 4);
(Note: π/4 = 45°.)
Solution 3
rotate to degree
#define degreesToRadians(x) (M_PI * (x) / 180.0)
then use / 90 is the degree:
button.transform=CGAffineTransformMakeRotation(degreesToRadians(90));
Solution 4
The Swift version:
button.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_4))