Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7545987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:04:55+00:00 2026-05-30T09:04:55+00:00

I have created a UIView – (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self)

  • 0

I have created a UIView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code

        UIImage *image2 = [UIImage imageNamed:@"pinGreen_v1.png"];
        UIImage *image1 = [UIImage imageNamed:@"PinDown1.png"];

        UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 10, 40, 40)];
        [btn1 setImage:image2 forState:UIControlStateNormal];
        [self addSubview:btn1]; 

        for(int i =1; i<20; i++){
            UIButton *btn2 = [[UIButton alloc]initWithFrame:CGRectMake(40 * i, 40, 40, 40)];
            [btn2 setImage:image1 forState:UIControlStateNormal];
            [btn2 addTarget:self 
                     action:@selector(buttonPressed) 
           forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btn2];
        }

    }
    return self;
}

With the above code I am drawing images in my view. I am loading this view from my view controller. I need to put this view inside a UIScrollview. Where should I create the scroll view? In the above view or the view controller where the above view is created.

The code inside my view controller is :

 DrawLineInMyClass *drawLines = [[DrawLineInMyClass alloc]initWithFrame:CGRectMake(0, 0, 320, 400)];
 drawLines.backgroundColor = [UIColor blackColor];
 [self.view addSubview:drawLines];
 [drawLines release];

I should be able to scroll through the images inside my view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:04:57+00:00Added an answer on May 30, 2026 at 9:04 am

    I would create the the scrollview in the viewcontroller and add the view to it.

    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    scroll.pagingEnabled = YES;
    
    DrawLineInMyClass *drawLines = [[DrawLineInMyClass alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
    drawLines.backgroundColor = [UIColor blackColor];
    [self.view addSubview:drawLines];
    
    [scroll addSubview:drawLines];
    
    scroll.contentSize = CGSizeMake(self.view.frame.size.width*drawLines.frame.size.width, self.view.frame.size.height);
    [self.view addSubview:scroll];
    [drawLines release];
    [scroll release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a UIView through code and want to add some images and
I have created customize UIView with following code .....it's running with no issue....but when
Does anyone have any sample code for detecting touches on a dynamically created UIView?
Suppose I have created a UIView , MyView , in Interface Builder, and I
I am new to iphone development.I have created a UIview controller class and added
I have created a UIView as a subview and to that subview I have
I have created a UIScrollView (canvas.scrollview) and have a custom UIView (canvas) inside it.
Can someone help me on how to make make UIView created in code to
I have created a simple UIView hierarchy in IB: Parent (UIView) child (UIView) child
I have a UIView (created in IB) with a grouped UITableView as a subview.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.