想要更改图像栏按钮项目图像

时间:2012-11-01 08:07:59

标签: iphone ios uitoolbaritem

我已经创建了一个AVFoundation Camera,现在我想将工具栏项目图像更改为我的自定义图像,当用户点击记录相机按钮时,图像会发生变化。

我做了那个改变,但问题是我的图像显示黑白没有color.soplz帮助。

我的代码是:

- (void)viewDidLoad

{
[[self recordButton] setImage:[UIImage imageNamed:@"camara30.png"]]  //first time setting image
}

- (void)captureManagerRecordingBegan:(AVCamCaptureManager *)captureManager
{
    CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopCommonModes, ^(void) {
       // [[self recordButton] setTintColor:[UIColor redColor]];
        [[self recordButton] setImage:[UIImage imageNamed:@"record30.png"]];   //changing image when record begun
        [[self recordButton] setEnabled:YES];
    });
}

- (void)captureManagerRecordingFinished:(AVCamCaptureManager *)captureManager
{
    CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopCommonModes, ^(void) {
        [[self recordButton] setImage:[UIImage imageNamed:@"camara30.png"]];   //changing image when record end
        [[self recordButton] setEnabled:YES];
    });
}

开始录制前的第一个屏幕:

enter image description here

结束录制后的第二个屏幕:

enter image description here

2 个答案:

答案 0 :(得分:0)

    UIBarButtonItem *temp = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"BlueMarbleDrop"] forState:UIControlStateNormal];
    button.frame=CGRectMake(0.0, 0.0, 60.0, 30.0);
    [button addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* stopBtn = [[UIBarButtonItem alloc] initWithCustomView:button];

    [self.toolBar setItems:[NSArray arrayWithObjects:temp,stopBtn,temp, nil]];

输出看起来像 enter image description here

我从UIBarButtonItem with color?

取得了这个

答案 1 :(得分:0)

尝试设置图像         [[self recordButton] setImage:[UIImage imageNamed:@" record30.png"] forState:UIControlStateNormal];