How to rotate uibutton like this in iphone sdk

5 answers

If you have an IBOutlet object.

theButton.transform = CGAffineTransformMakeRotation(M_PI / -4); 

If you want to create a runtime button in a 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]; } 
+9
source
 theButton.transform = CGAffineTransformMakeRotation(-M_PI / 4); 

(Note: π / 4 = 45 °.)

+4
source

I recently did this, I rotate button 5 at different angles.

here is an example:

  UIButton *typewritterButton = [UIButton buttonWithType:UIButtonTypeCustom]; typewritterButton.frame = CGRectMake(15, 165, 130, 25); typewritterButton.transform = CGAffineTransformMakeRotation((0.0174)*135); [m_overlay addSubview:typewritterButton]; 

This will definitely work for you ...

use CGAffineTransformMakeRotation((0.0174)*135);

just change the value 135, which is the angle at which you want to rotate the object ...

Let me know if there are any problems.

+1
source

rotate to a degree

 #define degreesToRadians(x) (M_PI * (x) / 180.0) 

then use / 90 - degree:

 button.transform=CGAffineTransformMakeRotation(degreesToRadians(90)); 
+1
source

Swift Version:

button.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_4))

+1
source

Source: https://habr.com/ru/post/1315892/


All Articles