gpt4 book ai didi

ios - 将按钮图像设置为从 xcode 库中选择的图像

转载 作者:行者123 更新时间:2023-11-29 04:00:14 25 4
gpt4 key购买 nike

我正在制作一个应用程序,我在其中选择一个按钮,它会引导我到库中选择一张图片。我希望所选图片成为按钮的主图像。谁能帮帮我?

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

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

任何帮助将不胜感激!

谢谢

最佳答案

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

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

完成。

关于ios - 将按钮图像设置为从 xcode 库中选择的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15955398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com