自定义ToolBar for iPhone App

时间:2014-01-03 22:58:37

标签: ios iphone uibarbuttonitem uitoolbar

我想更改我的UIBarButtonItems的图像,但没有色调,也没有调整大小。 使用导航栏中的按钮就可以了。

这是我的方法:

    UIButton *mySettingsButton = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *settingsImage = [UIImage imageNamed:@"settings-greyscale.png"];
    mySettingsButton.frame = CGRectMake(0.0, 0.0, settingsImage.size.width, settingsImage.size.height);
    [mySettingsButton setBackgroundColor:[UIColor clearColor]];
    [mySettingsButton setImage:settingsImage forState:UIControlStateNormal];
    [mySettingsButton addTarget:self action:@selector(performSettingsSegue)  forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *mySettingsBarButton = [[UIBarButtonItem alloc] initWithCustomView:mySettingsButton];
    UIBarButtonItem *settingsBarButton = (UIBarButtonItem *)[self.view viewWithTag:1000];
    settingsBarButton = mySettingsBarButton;

我不知道该怎么做。甚至可以在工具箱中删除BarButtonItem的色调?我只是希望我的图像没有任何变化。 我该怎么办?

提前致谢!

1 个答案:

答案 0 :(得分:0)

问题在于你的UIButton初始化代码,试试这个:

UIButton *mySettingsButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *settingsImage = [UIImage imageNamed:@"settings-greyscale.png"];
mySettingsButton.frame = CGRectMake(0.0, 0.0, sttingsImage.size.width, settingsImage.size.height);
/* then your code */