1

我想将导航栏按钮图像旋转 45 度。我使用以下代码来执行此操作

    CGAffineTransform cgaRotateHr = CGAffineTransformMakeRotation(-(3.141/2));
    [self.button setTransform:cgaRotateHr];

它适用于其他按钮图像,但不适用于导航栏按钮。我不明白这种意外行为的原因是什么。任何帮助是极大的赞赏 ....

4

2 回答 2

1

尝试使用此代码创建新的栏按钮项,然后将其设置为导航栏的左/右

+ (UIBarButtonItem *) barItemWithImage:(UIImage *)img size:(CGSize)size target:(id)target action:(SEL)selector
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    [button setImage:img forState:UIControlStateNormal];

    button.frame= CGRectMake(0.0, 0.0, size.width, size.height);

    [button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];

    // your transform code
    CGAffineTransform cgaRotateHr = CGAffineTransformMakeRotation(-(3.141/2));
    [button setTransform:cgaRotateHr];

    UIBarButtonItem *forward = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];

    return forward;
}
于 2012-12-24T08:11:47.743 回答
0

我已经通过以下方式解决了这个问题......

  • 拖放一个UIViewat Bar 按钮项。
  • 拖放UIButton到此视图上。
  • 然后代码旋转,

    CGAffineTransform cgaRotateHr = CGAffineTransformMakeRotation(-(3.141/4));
    [self.button setTransform:cgaRotateHr];
    
于 2012-12-24T09:21:49.087 回答