Мне нужно добавить маленькую красную точку в UIButton. Я устанавливаю цвет пользовательского UIButton, используя этот метод:
+ (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;
}
Затем мне нужно просто добавить к этой кнопке простую красную точку, которая предположительно делается следующим образом:
+ (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;
}
Но он просто возвращает белое изображение. Этот клиентский код:
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];
}
Как правильно добавить маленькую красную точку в существующий CGContext?