【问题标题】:Set button image as selected image from library in xcode在 xcode 中将按钮图像设置为从库中选择的图像
【发布时间】:2013-04-04 00:55:38
【问题描述】:

我正在制作一个应用程序,我在其中选择一个按钮,它会引导我到图书馆选择一张图片。我希望选择的图片成为按钮的主图像。 有人可以帮帮我吗?

这是我用来访问库的代码:

- (IBAction)image1Pressed:(id)sender {

if([UIImagePickerController isSourceTypeAvailable:
    UIImagePickerControllerSourceTypePhotoLibrary])
{
    UIImagePickerController *picker1= [[UIImagePickerController alloc]init];
    picker1.delegate = self;
    picker1.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:picker1 animated:YES completion:nil];
    [picker1 release];
}
}

任何帮助将不胜感激!

谢谢

【问题讨论】:

    标签: ios xcode image button


    【解决方案1】:

    您需要为按钮创建一个插座,我们将其命名为“imageButton”。让图像选择器完成剩下的工作:

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *btnImage = [info objectForKey:UIImagePickerControllerOriginalImage];
        [imageButton setImage:btnImage forState:UIControlStateNormal];
    }
    

    完成。

    【讨论】:

    • 我还需要保持 IBAction *image1Pressed 连接吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-15
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多