Rakesh Bhatt
Rakesh Bhatt

Reputation: 4606

how to rotate uibutton like this in iphone sdk

alt text

how to rotate uibutton like this in iphone sdk.....

Upvotes: 4

Views: 10434

Answers (5)

user402982
user402982

Reputation:

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.

Upvotes: 2

SoftDesigner
SoftDesigner

Reputation: 5853

The Swift version:

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

Upvotes: 1

chrigu
chrigu

Reputation: 145

rotate to degree

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

then use / 90 is the degree:

button.transform=CGAffineTransformMakeRotation(degreesToRadians(90));

Upvotes: 1

sagarkothari
sagarkothari

Reputation: 24820

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];
}

Upvotes: 9

kennytm
kennytm

Reputation: 523514

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

(Note: π/4 = 45°.)

Upvotes: 4

Related Questions