将 UIButton 添加到 UIScrollView [英] Adding a UIButton to UIScrollView
问题描述
我正在尝试将 UIButton
添加到 UIScrollView
.
I am trying to add the UIButton
to UIScrollView
.
我添加了带有背景图像 *(size: 320 * 620)* 的 UIImageView
.然后我将这个 UIImageView
添加到 UIScrollView
,它工作正常.
I have added the UIImageView
with background image *(size: 320 * 620)*.
Then I added this UIImageView
to UIScrollView
, and It works fine.
但现在我想在以下位置添加 UIButton
:(60, 500);(在滚动后出现的屏幕下方).
But now I want to add UIButton
at position at : (60, 500); (below screen that would appear after scrolling).
我尝试了以下代码,但按钮添加在 UIView
上而不是滚动视图上.按钮未显示在顶部.
I have tried following code, but the button is added on UIView
not on scrollview. Button is not getting displayed on the top.
代码:
- (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];
}
推荐答案
它没有显示在顶部,因为您在添加 imageView 之前添加了它们.把 [scrollView addSubview:imageView];
放在 btnStartDate=[[UIButton alloc] initWithFrame:CGRectMake(60,500,100,20)];
it is not displayed at the top because you added them before you added the imageView.
Put [scrollView addSubview:imageView];
before btnStartDate=[[UIButton alloc] initWithFrame:CGRectMake(60,500,100,20)];
这篇关于将 UIButton 添加到 UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!