2009-12-17 69 views
0

我試圖添加UIButtonUIScrollView添加一個UIButton到的UIScrollView

我已經添加了與UIImageView背景圖像*(尺寸:320×620)*。 然後我說這個UIImageViewUIScrollView,並能正常工作。

但現在我想添加UIButton在位置:(60,500);(以下滾動後似乎該屏幕)。

我試過下面的代碼,但是在UIView上加上的按鈕不在scrollview上。按鈕是沒有得到顯示在頂部。

代碼:

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

回答

1

,因爲你加入他們,你添加的ImageView之前它不顯示在頂部。 btnStartDate=[[UIButton alloc] initWithFrame:CGRectMake(60,500,100,20)];

之前把 [scrollView addSubview:imageView];
相關問題