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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:42:49+00:00 2026-05-31T11:42:49+00:00

i programmatically insert a custom botton (image) in xCode. After a click on the

  • 0

i programmatically insert a custom botton (image) in xCode. After a click on the UIbutton i want to move the button to a custom place on the iPhone screen.

The programmatically button:

self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

    UIButton *MyButton = [UIButton buttonWithType:nil];

    MyButton.frame = CGRectMake(100, 170, 100, 30);

    [MyButton setImage:[UIImage imageNamed:@"tap.png"] forState:nil];

    [self.view addSubview:MyButton];

    [MyButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];

i’m trying to move the button after a click.

-(void)buttonPressed {
    NSLog(@"Button Pressed!");


    CGRect frame = MyButton.frame;
    frame.origin.x = 100; // new x coordinate
    frame.origin.y = 4; // new y coordinate

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration: 0.1];
    MyButton.frame = frame;
    [UIView commitAnimations];

    }

but nothing nothings happens.

I the .h file

IBOutlet UIButton *MyButton;
@property (nonatomic, retain) UIButton *MyButton;
  • 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-31T11:42:50+00:00Added an answer on May 31, 2026 at 11:42 am

    It would be easier to use an UIButton, because they already listen for tap events. Otherwise you will need to add an UIGestureRecognizer to your UIImageView. Once you have your UIButton set up in Interface Builder and connected to an IBOutlet, you can use this same code to move it.

    EDIT

    Your problem may be that you are creating a new button instead of assigning to your MyButton property. Instead of:

    UIButton *MyButton = [UIButton buttonWithType:nil];
    

    try:

    MyButton = [UIButton buttonWithType:UIButtonTypeCustom]; // UIButtonTypeCustom is what you would need to properly display your image. If you aren't setting an image for the button yet, then instead try UIButtonTypeRoundedRect.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I insert a DVD or CD, I want to programmatically know what type
As the subject says I want to insert an image into the 2nd column
I'm currently trying to programmatically insert a ModelClientValidationStringLengthRule ModelValidator via a custom attribute, and
I would like to programmatically insert additional rows into a DataGrid (to act as
What's the better way to insert cell comments in excel 2007 files programmatically using
I need to programmatically insert a row into an Excel Spreadsheet multiple times. I
How can i insert data programmatically? but i can not do that. No error
I am trying to insert a new call on my HTC programmatically. ContentValues values
I am trying to insert Call Logs in inbox programmatically but I am using
I tried searching on the net to programmatically insert a List as a webpart

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.