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 8593341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:57:58+00:00 2026-06-11T23:57:58+00:00

I have made a sample where there is a ScrollView and Images that Scroll

  • 0

I have made a sample where there is a ScrollView and Images that Scroll in the ScrollView. When You Click on One on the Images it tells you what button image is pressed below the UIScrollView in form of a UILabelView. What I want to figure out is How do I change the Label to a UIImageView. So instead of it saying button %d when pushed. I want to show a image that i stipulate.

Kitchens.h

#import <UIKit/UIKit.h>
#import "SlideMenuView.h"


@interface Kitchens : UIViewController {
IBOutlet UIScrollView *windows;
SlideMenuView *slideMenuView;
UILabel *screenLabel;
}

@property (nonatomic, retain) UIScrollView *windows;
@property (nonatomic, retain) SlideMenuView *slideMenuView;
@property (nonatomic, retain) UILabel *screenLabel;

@end

Kitchens.m

#import "Kitchens.h"
#import "SlideMenuView.h"

@interface Kitchens ()

@end

@implementation Kitchens

@synthesize windows, slideMenuView, screenLabel;
#pragma mark -
#pragma mark <Touches Began/Moved/Ended/Cancelled Methods>


- (void)viewDidLoad {


// Create and position a label
screenLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 200.0f, [windows bounds].size.width-20.0f, 20.0f)];
[windows addSubview:screenLabel];

// Create buttons for the sliding menu. For simplicity I create 5 standard buttons.
NSMutableArray* buttonArray = [[NSMutableArray alloc] init];

for(int i = 0; i < 5; i++)
{
// Rounded rect is nice
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

// Give the buttons a width of 100 and a height of 30. The slide menu will take care of positioning the buttons.
// If you don't know that 100 will be enough, use my function to calculate the length of a string. You find it on my blog.

[btn setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
[btn setTitle:[NSString stringWithFormat:@"Button %d", i+1] forState:UIControlStateNormal];

[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[btn setImage:[UIImage imageNamed:@"test.jpg"] forState:UIControlStateNormal];
[buttonArray addObject:btn];

// Rounded rect is nice
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];

// Give the buttons a width of 100 and a height of 30. The slide menu will take care of positioning the buttons.
// If you don't know that 100 will be enough, use my function to calculate the length of a string. You find it on my blog.

[btn1 setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
[btn1 setTitle:[NSString stringWithFormat:@"Button2"] forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[btn1 setImage:[UIImage imageNamed:@"pia05733-640-480.jpg"] forState:UIControlStateNormal];
[buttonArray addObject:btn1];

UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// Give the buttons a width of 100 and a height of 30. The slide menu will take care of positioning the buttons.
// If you don't know that 100 will be enough, use my function to calculate the length of a string. You find it on my blog.
[btn2 setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
[btn2 setTitle:[NSString stringWithFormat:@"Button3"] forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[btn2 setImage:[UIImage imageNamed:@"pia05733-640-480.jpg"] forState:UIControlStateNormal];
[buttonArray addObject:btn2];

}

// initialize the slide menu by passing a suitable frame, background color and an array of buttons.
slideMenuView = [[SlideMenuView alloc] initWithFrameColorAndButtons:CGRectMake(10.0f, 30.0f, [windows bounds].size.width-20.0f,  100.0f) backgroundColor:[UIColor blackColor]  buttons:buttonArray];

// Add the slide menu to the window.
[windows addSubview:slideMenuView];


[super viewDidLoad];


}

- (IBAction)buttonPressed:(id)sender {
screenLabel.text = ((UIButton*)sender).currentTitle;
UIButton *btn2 = (UIButton*)sender;
UIImage *image = btn2.currentImage;

// Set the image in the image view
self.imageView.image = image;

}

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
    return YES;
}
}

@end

SlideMenuView,h

#import <UIKit/UIKit.h>

@interface SlideMenuView : UIView <UIScrollViewDelegate> {
UIScrollView *menuScrollView;
UIImageView *rightMenuImage;
UIImageView *leftMenuImage;
NSMutableArray *menuButtons;
}
-(id) initWithFrameColorAndButtons:(CGRect)frame backgroundColor:(UIColor*)bgColor  buttons:(NSMutableArray*)buttonArray;

@property (nonatomic, retain) UIScrollView* menuScrollView;
@property (nonatomic, retain) UIImageView* rightMenuImage;
@property (nonatomic, retain) UIImageView* leftMenuImage;
@property (nonatomic, retain) NSMutableArray* menuButtons;

@end

SlideMenuView.m

#import "SlideMenuView.h"


@implementation SlideMenuView
@synthesize menuScrollView, rightMenuImage, leftMenuImage;
@synthesize menuButtons;

-(id) initWithFrameColorAndButtons:(CGRect)frame backgroundColor:(UIColor*)bgColor  buttons:(NSMutableArray*)buttonArray  {

if (self = [super initWithFrame:frame]) {

    // Initialize the scroll view with the same size as this view.
    menuScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height)];

    // Set behaviour for the scrollview
    menuScrollView.backgroundColor = bgColor;
    menuScrollView.showsHorizontalScrollIndicator = FALSE;
    menuScrollView.showsVerticalScrollIndicator = FALSE;
    menuScrollView.scrollEnabled = YES;
    menuScrollView.bounces = FALSE;

    // Add ourselves as delegate receiver so we can detect when the user is scrolling.
    menuScrollView.delegate = self;

    // Add the buttons to the scrollview
    menuButtons = buttonArray;

    float totalButtonWidth = 0.0f;

    for(int i = 0; i < [menuButtons count]; i++)
    {
        UIButton *btn = [menuButtons objectAtIndex:i];

        // Move the buttons position in the x-demension (horizontal).
        CGRect btnRect = btn.frame;
        btnRect.origin.x = totalButtonWidth;
        [btn setFrame:btnRect];

        // Add the button to the scrollview
        [menuScrollView addSubview:btn];

        // Add the width of the button to the total width.
        totalButtonWidth += btn.frame.size.width;
    }

    // Update the scrollview content rect, which is the combined width of the buttons
    [menuScrollView setContentSize:CGSizeMake(totalButtonWidth, self.frame.size.height)];

    [self addSubview:menuScrollView];

}
return self;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// if the offset is less than 3, the content is scrolled to the far left. This would be the time to show/hide
// an arrow that indicates that you can scroll to the right. The 3 is to give it some "padding".
if(scrollView.contentOffset.x <= 3)
{
    NSLog(@"Scroll is as far left as possible");
}
// The offset is always calculated from the bottom left corner, which means when the scroll is as far
// right as possible it will not give an offset that is equal to the entire width of the content. Example:
// The content has a width of 500, the scroll view has the width of 200. Then the content offset for far right
// would be 300 (500-200). Then I remove 3 to give it some "padding"
else if(scrollView.contentOffset.x >= (scrollView.contentSize.width - scrollView.frame.size.width)-3)
{
    NSLog(@"Scroll is as far right as possible");
}
else
{
    // The scoll is somewhere in between left and right. This is the place to indicate that the 
    // use can scroll both left and right
}

}

- (void)drawRect:(CGRect)rect {
// Drawing code
}


- (void)dealloc {
//[menuButtons release];
//[rightMenuImage release];
//[leftMenuImage release];
//[menuScrollView release];
// [super dealloc];
}


@end

enter image description here

  • 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-06-11T23:57:59+00:00Added an answer on June 11, 2026 at 11:57 pm

    In button Action method, get the current background image for that button and set it in an image view

     - (IBAction)buttonPressed:(id)sender {
             UIButton *button = (UIButton*)sender;
             UIImage *image = button.currentBackgroundImage;
    
              // Set the image in the image view
    
    
             self.imageView.image = image;
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a population and a sample of that population. I've made a few
In my application i have two images original upper image and down reflection one.
I have made a sample for posting on Facebook using the basic Facebook library
I have made a sample application which constructs a filter graph to capture audio
I have made simple encryption/decryption method in php that I'm trying to move to
I have made an app that paints FFT to the screen realtime (from mic).
I have a custom control library with a resouce dictionary that references an image
I have made an app that sets notifications in the drop-down status bar of
I have made a simple chat application in PHP/Ajax/MySQL. I am regularly calling these
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big

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.