1

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

我已经完成了这项更改,但问题是我的图像显示为黑白,没有颜色。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];
    });
}

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

在此处输入图像描述

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

在此处输入图像描述

4

2 回答 2

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]];

输出看起来像 在此处输入图像描述

我从UIBarButtonItem 拿了这个颜色?

于 2012-11-01T08:35:22.413 回答
0

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

于 2012-11-01T10:44:06.433 回答