我正在尝试将UIButton
添加到UIScrollView
。
我添加了UIImageView
背景图片*(尺寸:320 * 620)*。
然后我将此UIImageView
添加到UIScrollView
,并且工作正常。
但现在我想在位置添加UIButton
:(60,500); (滚动后会出现的屏幕下方)。
我已尝试使用以下代码,但该按钮已添加到UIView
而不是滚动视图上。按钮未显示在顶部。
代码:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.hidden = TRUE;
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SingleModelVar.png"]];
self.imageView = tempImageView;
[tempImageView release];
imageView.userInteractionEnabled = YES;
scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; //fit to screen
//scrollView.delaysContentTouches = NO;
scrollView.contentSize = CGSizeMake(320, imageView.frame.size.height); //imageView.frame.size.height=620 here
scrollView.maximumZoomScale = 4.0;
scrollView.minimumZoomScale = 0.75;
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
//The Problem begins ..........
btnStartDate=[[UIButton alloc] initWithFrame:CGRectMake(60,500,100,20)];
[scrollView addSubview:btnStartDate];
//[self.view addSubview:btnStartDate];
btnEndDate=[[UIButton alloc] initWithFrame:CGRectMake(60,530,100,20)];
[scrollView addSubview:btnEndDate];
//[self.view addSubview:btnEndDate];
[scrollView addSubview:imageView];
[[self view] addSubview:scrollView];
}
答案 0 :(得分:1)
它不会显示在顶部,因为您在添加imageView之前添加了它们。
将[scrollView addSubview:imageView];
放在btnStartDate=[[UIButton alloc] initWithFrame:CGRectMake(60,500,100,20)];