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

  • Home
  • SEARCH
  • 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 6246437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:41:21+00:00 2026-05-24T12:41:21+00:00

I am adding a custom view on main window then on the view i

  • 0

I am adding a custom view on main window then on the view i am creating a button and button is showing but the action is not performing on button tapped.
on a button tap i want to open a photogallery.
and in a loop the buttons are created.

code that i am using is there…

UIImage *image=[[UIImage alloc] initWithData:data cache:NO];
UIImageView *iv=[[UIImageView alloc] initWithFrame:CGRectMake(200, y, 75, 75)];

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(200, y, 75, 75)];
[button setAlpha:0];
[button setTag:i];//change this to your loop counter
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];  

iv.image=image;
//  iv.tag=@"bigimage.jpg";
iv.userInteractionEnabled=YES;
button.userInteractionEnabled = YES;

[iv addSubview:button];
[button release];

y=y+145;
[view1 addSubview:iv];
[iv release];

And also try this code but no improvements are there…..

UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(200, y, 75, 75);
        UIImage *img = [[UIImage alloc] initWithData:data];
        [button setBackgroundImage:img forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = i;
        y = y+145;
        [view1 addSubview:button];
  • 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-24T12:41:23+00:00Added an answer on May 24, 2026 at 12:41 pm

    Hello Shivangi,

             I think you want to set image on button so try this code its will help you
    
    
    
              //function to create button dynamically on scrollview
              -(void)createButton
               {
                int Y = 20;
                indexRow = 0;
                for (int i = 0; i < [prow.noOfPhotos count]; i++) 
                {
                  thumbNailButton = [UIButton buttonWithType:UIButtonTypeCustom];       
                  int X = 4 + (78 * (i % 4));
                  NSLog(@"X = %d",X);
    
                  NSLog(@"Start Y = %d",Y);
                  if (i % 4 == 0) 
                  {
                NSLog(@"%d",i);
                Y = (70 * verticalImageRowCount);
                NSLog(@"Y = %d",Y);
                verticalImageRowCount++;
                NSLog(@"VerticalImageRowCount= %d");
                  } 
    
                  CGRect rect = myScrollView.frame;
                   rect.size.width = 100;
                   rect.size.height = Y + 77; 
                   myScrollView.contentSize = CGSizeMake(rect.size.width,rect.size.height);
                   thumbNailButton.frame = CGRectMake(X,Y, 62,65);
    
                   view = [[UIImageView alloc] init];
    
                   prow.photo = [prow.noOfPhotos objectAtIndex:indexRow];
    
                   imagePath = prow.photo;
                   asyncImageView = [[[AsyncImageView alloc] initWithFrame:CGRectMake(4, 0, 62, 65)] autorelease];
                   asyncImageView.backgroundColor = [UIColor clearColor];
                   [view addSubview:asyncImageView];
    
                   NSURL *url = [NSURL URLWithString:imagePath];
                   [asyncImageView loadImageFromURL:url];           
                   [view setImage:[UIImage imageNamed:[prow.noOfPhotos objectAtIndex:i]]];
    
                   thumbNailButton.tag = i;
                   thumbNailButton.backgroundColor=[UIColor clearColor];
                       [thumbNailButton addTarget:self action:@selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];   
                   [thumbNailButton addSubview:view];
                   [myScrollView addSubview:thumbNailButton];
                   indexRow+= 1;
    
                    }
                    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on adding a custom accessory view, (a button) to a UITableViewCell,
Im creating and adding a grid of buttons to my custom view keyboardView as
I am adding a custom background image to my navigation bar by creating an
I'm creating a custom (layer-hosting) document view, which is contained within a scroll view.
I'm programatically adding two custom UIPickerViews to another view (MainView). They work just fine
In application:didFinishLaunchingWithOptions: I'm adding a split view: [self.window addSubview:splitViewController.view]; [self.window makeKeyAndVisible]; splitViewController comes from
I've got a custom BaseAdapter and an add button in the main activity. The
I have a UITableView and I am adding custom view to the cell. It
I'm adding a custom View to the parent layout, witch is a RelativeLayout. I
I've setup an own class(custom UIView). I'am adding two of these customViews to my

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.