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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:55:33+00:00 2026-06-16T10:55:33+00:00

Possible Duplicate: create UIImageView with portion of image file I have setup a series

  • 0

Possible Duplicate:
create UIImageView with portion of image file

I have setup a series of buttons of around 30px x 30px. I have an image of size 300px x 300px.

When I set the image as either the image or the background image the image is automatically resized to fit into the button. What I would actually like it to do is to display a 30 x 30 section of the image.

I have tried several methods for doing this however they appear to be fruitless. I have tried over riding -(void)layoutSubviews but this caused the image to be bigger than the button itself and caused other odd behaviours.

I have also tried modifying the image view property but again this also did not work.

Lastly I have tried using imageEdgeInsets but again this had similar behaviour of over riding layoutSubviews.

I would like to do this as I have a numerous buttons that will make up the full picture but these will be moving. An alternative way would be to split the image up in a paint style package but in the long run this will cause extra work and would prefer to do this programatically. Any guidance on how to proceed would be appreciated.

  • 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-16T10:55:34+00:00Added an answer on June 16, 2026 at 10:55 am

    After posting the question I investigated further and came across the following.

    Some of the aspects of this are very similar to the question located at create UIImageView with portion of image file

        UIImage* img = [UIImage imageNamed:currentImage];
        CGRect imgFrame = CGRectMake(x, y, 30, 30);
        CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], imgFrame);
        UIImage* subImage = [UIImage imageWithCGImage: imageRef];
        [imageButton setBackgroundImage:subImage forState:UIControlStateNormal];
    

    once this is done subImage can simply be added as the image for the uibutton such as:-

        [imageButton setBackgroundImage:subImage forState:UIControlStateNormal];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to create XSD file programmatically in C#? I have an XDocument
Possible Duplicate: Create an alert on any view controller after Facebook request:didFailWithError: I have
Possible Duplicate: Create Excel file in Java How to save output in excel format
Possible Duplicate: PHP create a file without fopen I want to create a file
Possible Duplicate: How do you create an application shortcut (.lnk file) in C# or
Possible Duplicate: Create a file in /system directory First of all, i gave the
Possible Duplicate: Create Excel (.XLS and .XLSX) file from C# Rounding double values in
Possible Duplicate: how to create proportional image height/width The height should be adjusted proportional
Possible Duplicate: How to create comma separated list from array in PHP? I have
Possible Duplicate: Create Browser-Bookmark from app I have tried to create a bookmark for

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.