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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:41:54+00:00 2026-05-12T09:41:54+00:00

I have an UIView which I want to give a gradient background and I’m

  • 0

I have an UIView which I want to give a gradient background and I’m wondering how to implement that as efficient as possible.

I am considering three options:

  1. Create an UIImageView as subview and give it an image of the gradient to display.

  2. Draw the gradient image in drawRect: of the original UIView.

  3. Draw the gradient in drawRect:, but this time use CoreGraphics to ‘create it from scratch’.

Which of these three would be the fastest/least memory intensive?
(The fastest to run, not to write.)

Thanks!

  • 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-12T09:41:54+00:00Added an answer on May 12, 2026 at 9:41 am
    • Creating a UIImageView as a subview of the main view would be the quickest way to get what you want.
    • Drawing the image onto the view’s context would be the more memory intensive option.
    • Drawing the gradient in code using Core Graphics would be the more efficient way.

    Things to keep in mind:

    You have little-to-no control over when how often drawRect executes, so you don’t want to be doing things like memory allocation within that method.

    drawRect could be called more than once in the same run loop, so it’s not a good idea to create autoreleased objects during that method either, because they may stack up and consume more memory than necessary.

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

Sidebar

Related Questions

I have a UIView which I want to have a radial gradient, and I'm
So I have a UIView which has a UIWebView and I want so that
I have a UIView of which I want to know when the user is
I have a UIView of size width=320px height=40px which I want to display at
I have an UIImage which I want to draw on a UIView . But
I have one UIView, which I'm using as my main view, and I want
I have code that creates, adds and tags unbuttons in a uiview which is
I have this XML i want display all fields on the uiview which comes
Let's say I have a UIView that contains a child UIView which has to
I have UIView in which I want to be able to drag and drop

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.