xcode 如何在iphone sdk中像这样旋转uibutton
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3263576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to rotate uibutton like this in iphone sdk
提问by Rakesh Bhatt
回答by Sagar R. Kothari
If you have an IBOutlet Object.
如果您有一个 IBOutlet 对象。
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];
}
回答by kennytm
theButton.transform = CGAffineTransformMakeRotation(-M_PI / 4);
(Note: π/4 = 45°.)
(注:π/4 = 45°。)
回答by kennytm
Recently i have done this, I rotate 5 button in different angles.
最近我做了这个,我在不同的角度旋转了 5 个按钮。
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);
用这个 CGAffineTransformMakeRotation((0.0174)*135);
just change the value of 135 that is the angle in which you want to rotate the object.
只需更改值 135,即您要旋转对象的角度。
Let me know if there is any problem.
如果有任何问题,请告诉我。
回答by chrigu
rotate to degree
旋转到一定程度
#define degreesToRadians(x) (M_PI * (x) / 180.0)
then use / 90 is the degree:
那么使用/90就是度数:
button.transform=CGAffineTransformMakeRotation(degreesToRadians(90));
回答by SoftDesigner
The Swift version:
斯威夫特版本:
button.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_4))
button.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_4))