CGContextRotateCTM没有旋转UIButton

时间:2011-12-23 04:46:45

标签: iphone ios uibutton core-graphics

我有一个UIButton的子类。

以下是我必须尝试旋转它的代码。

-(void)drawRect:(CGRect)rect {

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGFloat angle = (-126.0 * M_PI) / 180.0;
    CGContextRotateCTM(context, angle);
}

但是,什么都没发生。视图以默认方向绘制到屏幕。知道我错过了什么吗?谢谢!

1 个答案:

答案 0 :(得分:2)

通常,当您想要旋转按钮时,不要通过子类化和修改drawRect来完成。

您所要做的就是:

button.transform = CGAffineTransformMakeRotation(M_PI/2);