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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:19:39+00:00 2026-06-03T06:19:39+00:00

I would like to create my own subclass of UIImage that would allow me

  • 0

I would like to create my own subclass of UIImage that would allow me to create a realizable/stretchable image with caps on each of the four sides.

iOS 5’s resizableImage does not fit my needs since it does not allow me to stretch the middle part, neither does the now deprecated stretchableImage because it allows me to repeat only a single pixel, while I may want to repeat some sort of gradient.

So far everything works fine, I implemented my own drawing code in -drawInRect: and it behaves as expected.
However, when assigning my custom subclass instance as a UIImageView‘s image, my code breaks. The image gets rendered as the normal UIImage would. (scaled in all directions without any caps)

I tried to set breakpoints at all of the four drawing methods (drawInRect, drawAtPoint, both standalone plus with blendMode: but they seem not to get called.

Is there a way to provide a UIImage with custom drawing code when using it within a UIImageView without subclassing UIImageView, too?

Also, I am worrying about performance. The default stretchable image works quite well during animations, but I wonder how it’d be when animating size properties (width & height) of my UIImageView. Would my rendering code get called every frame?

  • 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-03T06:19:40+00:00Added an answer on June 3, 2026 at 6:19 am

    In the Apple Documentation it clearly says you can’t override -drawRect: of a UIImageView, so subclassing UIImageView will not work also. You have to implement your own UIView class.

    Subclassing UIImage will neither work, I have tried this and no public method was called at all, not even the accessory method for CGImage. I think you would need to override some private API to make this work.

    Don’t worry about resizing, your rendering code will only be called for the final frame.
    Still, in most cases performance is worse than using an UIImageView. Apple optimized the class so it runs on the GPU.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a subclass of DispatcherObject to create my own thread-affined
I would like create my own collection that has all the attributes of python
So I have five different UIViewController that I would like to create. Each of
I would like to create my own data format for an iPhone app. The
I would like to create a c++ type that mimic the build-in type exactly.
I would like to create a class that runs something (a runnable) at regular
I would like to create my own database server for educational purposes. My problem
I would like to create my own google maps mash up exactly like wundermaps
I would like to create my own events. In action script 3 I can
I'd like to create a subclass of UIAlertView to implement my own defaut behaviors

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.