0

我在 xcode 4 中制作了一个 ios 应用程序,需要制作一个UIScrollView包含按钮和UIImageView. 有谁知道如何编码?

(如果可能的话,我希望能够在情节提要中做到这一点)

谢谢

4

1 回答 1

9

ViewDidLoad方法:

// 添加滚动视图

UIScrollView *scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,480)]; 
scrollview.showsVerticalScrollIndicator=YES;
scrollview.scrollEnabled=YES;
scrollview.userInteractionEnabled=YES;
[self.view addSubview:scrollview];
scrollview.contentSize = CGSizeMake(320,960);//You Can Edit this with your requirement 

// 添加按钮

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);
[scrollview addSubview:button];

//添加图像视图

UIImageView*   iv =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourPhoto.png"]];
iv.frame=CGRectMake(0, 0, 40,60);
[scrollview addSubview:iv];
于 2012-10-14T06:27:21.673 回答