没有视图控制器或任何界面构建器,我只想用代码构建它。我有方法设置,您可以单击按钮转到相机胶卷,但现在我不知道下一步该做什么。我需要一种选择图像的方法,它允许我将图像添加到图像视图中。任何关于做什么的提示将不胜感激。
- (void)viewDidLoad {
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
[self.view addSubview: imgView];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
}
-(void)aMethod{
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsImageEditing = YES;
[[self navigationController] presentModalViewController:picker animated:YES];
}