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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:56:52+00:00 2026-05-30T05:56:52+00:00

Is there a way to create a colored fill pattern dynamically in Cocoa? In

  • 0

Is there a way to create a colored fill pattern dynamically in Cocoa?

In particular instead of using a fixed pattern from an image file via

NSColor *fillPattern = [NSColor colorWithPatternImage:patternImage];

I’d like to create a pattern by dynamically choosing the appropriate colors at runtime.
Background is highlighting a colored object by rendering stripes or squares in the ”opposite” color on top of it – whatever opposite might mean in this context, but that’s a different story..

Being applied to potentially hundreds of objects in a drawing app it needs to be a rather fast method so I suppose just swapping colors in patternImage won’t be good enough.

(It did work just fine back in QuickDraw..!)

  • 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-30T05:56:54+00:00Added an answer on May 30, 2026 at 5:56 am

    Why not just draw to an in-memory image and use that for your pattern?

    NSImage* patternImage = [[NSImage alloc] initWithSize:someSize];
    [patternImage lockFocus];
    //draw your pattern
    [patternImage unlockFocus];
    NSColor* patternColor = [NSColor colorWithPatternImage:patternImage];
    //do something with the pattern color
    //remember to release patternImage if you're not using ARC
    

    Performance-wise, you generally should be looking at optimising drawing by paying attention to the rect passed in to drawRect: and making sure you only draw what is necessary. If you do that then I can’t see the pattern drawing performance being a major problem.

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

Sidebar

Related Questions

Is there easy way to create FILE* from WinApi HANDLE which points to one
Is there a way to create an html link using h:outputLink, other JSF tag
Is there a way to create C# objects and call methods from unmanaged C++,
Is there a way to create a Distinct query in HQL. Either by using
Is there a way to create a SmartArt Hierarchy chart in Word from a
Is there a way to create a batch or a text file to execute
Is there a way to create an uncompressed ZIP (level 0) from PHP? I
Is there any way to create dynamic vectors using jsp. Advance thanks to you
Is there any way to create animated app intro in cocos2d instead use of
Is there a way to create a JButton with your own button graphic and

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.