how to rotate uibutton like this in iphone sdk
how to rotate uibutton like this in iphone sdk.....
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];
}
theButton.transform = CGAffineTransformMakeRotation(-M_PI / 4);
(Note: π/4 = 45°.)
Recently i have done this, I rotate 5 button in different angles.
Here is the example:
UIButton *typewritterButton = [UIButton buttonWithType:UIButtonTypeCustom];
typewritterButton.frame = CGRectMake(15, 165, 130, 25);
typewritterButton.transform = CGAffineTransformMakeRotation((0.0174)*135);
[m_overlay addSubview:typewritterButton];
definitely it will work for you.
use this CGAffineTransformMakeRotation((0.0174)*135);
just change the value of 135 that is the angle in which you want to rotate the object.
Let me know if there is any problem.
rotate to degree
#define degreesToRadians(x) (M_PI * (x) / 180.0)
then use / 90 is the degree:
button.transform=CGAffineTransformMakeRotation(degreesToRadians(90));
The Swift version:
button.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_4))
精彩评论