代码之家  ›  专栏  ›  技术社区  ›  Rakesh Bhatt

如何在iPhone SDK中像这样旋转uibutton

  •  4
  • Rakesh Bhatt  · 技术社区  · 16 年前

    alt text http://www.freeimagehosting.net/uploads/e2f814743a.jpg

    如何在iPhone SDK中像这样旋转uibutton…..

    5 回复  |  直到 8 年前
        1
  •  9
  •   sagarkothari    15 年前

    如果你有一个iboutlet对象。

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

    如果要在视图上创建运行时按钮。

    - (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];
    }
    
        2
  •  4
  •   kennytm    16 年前
    theButton.transform = CGAffineTransformMakeRotation(-M_PI / 4);
    

    (注:_/4=45_度)

        3
  •  2
  •   guenis    8 年前

    最近我做了这个,我旋转5个按钮在不同的角度。

    示例如下:

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

    这肯定对你有用。

    用这个 CGAffineTransformMakeRotation((0.0174)*135);

    只需更改135的值,即要旋转对象的角度。

    如果有什么问题请告诉我。

        4
  •  1
  •   chrigu    10 年前

    旋转到度

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

    那么使用/90是度:

    button.transform=CGAffineTransformMakeRotation(degreesToRadians(90));
    
        5
  •  1
  •   SoftDesigner    10 年前

    Swift版本:

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