Adding a UIButton to UIScrollView


I am trying to add the UIButton to UIScrollView.

I have added the UIImageView with background image *(size: 320 * 620)*. Then I added this UIImageView to UIScrollView, and It works fine.

But now I want to add UIButton at position at : <em>(60, 500);</em> (below screen that would appear after scrolling).

I have tried following code, but the button is added on UIView not on scrollview. Button is not getting displayed on the top.

Code :

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


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)];


  • UITableView background Image
  • I can't show LinearLayout at bottom to scroll view
  • How to Update UILabel from Another ViewController
  • UIBarButtonItem - Argument of '#selector' cannot refer to local function - Swift 3
  • updatesearchresultsforsearchcontroller not called
  • UIPageViewController delegate method similar to scrollViewDidScroll:(UIScrollview*)scrollview
  • this class is not key value coding-compliant for the key PerformRotate
  • windowScriptObject method not found on Objective-C code
  • Printing input from TextField to a Label in Xcode with Swift
  • Custom font for MKAnnotationView Callout
  • Setting attributes of an EditText added dynamically in Android
  • Best practice for switching iPhone views?
  • css background images not always displayed
  • You tube videos are not playing
  • AJAX Html Editor Extender upload image appearing blank
  • Android fill_parent issue
  • Change multiple background-images with jQuery
  • Algorithm for a smudge tool?
  • Adding a button at the bottom of a table view
  • Can Jackson SerializationFeature be overridden per field or class?
  • Window Size for Mac application
  • jquery mobile loadPage not working
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • How to disable jQuery.jplayer autoplay?
  • Android Studio and gradle
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How to stop GridView from loading again when I press back button?
  • How can I remove ASP.NET Designer.cs files?
  • Bitwise OR returns boolean when one of operands is nil
  • EntityFramework adding new object to nested object collection
  • sending mail using smtp is too slow
  • Checking variable from a different class in C#
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • failed to connect to specific WiFi in android programmatically
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?