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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:45:36+00:00 2026-06-03T03:45:36+00:00

I have to add a small red dot to a UIButton. I set the

  • 0

I have to add a small red dot to a UIButton. I set the color of custom UIButton using this method:

+ (UIImage *) imageFromColor:(UIColor *)color {
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    //  [[UIColor colorWithRed:222./255 green:227./255 blue: 229./255 alpha:1] CGColor]) ;
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

Then I have just to add a simple red dot to this button which is assumably done like this:

+ (UIImage *) addRedDot 
{
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);
    //  [[UIColor colorWithRed:222./255 green:227./255 blue: 229./255 alpha:1] CGColor]) ;
    CGContextSetRGBStrokeColor(context, 1.0f, 0.0f, 0.0f, 1.0f);

    CGContextSetLineWidth(context, 2.0);
    CGContextStrokeEllipseInRect(context, CGRectMake(10, 11, 21, 21));

 //   CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

But it just returns a white image..
this client code is:

   if ([dateStringToAssign isEqualToString:[self dateToString:[NSDate date]]]) 
            {

                [buttonToLay setBackgroundImage:[CommonUIUtility imageFromColor:[UIColor cyanColor]] 
                                  forState:UIControlStateNormal];


            }
            if([dbm hasEventsForDate:buttonToLay.ownedDate])
            {
                NSLog(@"Has events");
                [buttonToLay setBackgroundImage:[CommonUIUtility addRedDot] forState:UIControlStateNormal];

            }

What’s the right way to add a small red dot to existing CGContext?

  • 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-03T03:45:38+00:00Added an answer on June 3, 2026 at 3:45 am

    You’re stroking an ellipse beyonds the bounds of the context you set up in this line:

    CGContextStrokeEllipseInRect(context, CGRectMake(10, 11, 21, 21));

    In order to have the ellipse show up, it needs to be within the bounds of your context, which appears to have size 1×1.

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

Sidebar

Related Questions

I have been using this website pretty often in order to solve small issues
I have a small problem, I have tried different solutions to add a image
I'm working on a project where I have to add a small preview pane
We have a Spring/Hibernate app and would like to add a small amount of
Can someone tell me where to add the small piece of code to have
I have a xml based Relative Layout and was attempting to add a small
I am building a small Blackberry app in which I have to add an
I have method which have to add customer: [WebInvoke(UriTemplate = /, Method = POST,
I have this small piece here - the text has text-indent So it will
Below I have a simple method for painting a set of objects onto an

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.