Welcome, Guest
Username Password: Remember me

UIColor doesn't conform to copy protocol
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: UIColor doesn't conform to copy protocol

UIColor doesn't conform to copy protocol 1 year, 1 month ago #1

Hi Tarek, afaik UIColor doesn't perform to the NSCopy protocol so this code will fail:

SCBadgeVIew.m
- (void)setColor:(UIColor *)_color
{
[color release];
color = [_color copy];

[self setNeedsDisplay];
}

To reproduce:

cell.badgeView.color = [UIColor colorWithRed:119/255.0 green:79/255.0 blue:56/255.0 alpha:1];

I changed copy with retain and it works.

Re: UIColor doesn't conform to copy protocol 1 year, 1 month ago #2

Hi Oscar,

You're absolutely right, thank you very much for reporting this! We'll fix it right away in our final 2.0 release (should be out tom. BTW).

Thanks again
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: UIColor doesn't conform to copy protocol 1 year, 1 month ago #3

Tarek, thanks. Another minor thing. If the cell selectionStyle is equal to UITableViewCellEditingStyleNone I think the badge view shouldn't be painted white. Here's I'm checking for the selectionStyle:


- (void)drawRect:(CGRect)rect
{
if(!self.text)
return;
 
UIColor *badgeColor = self.color;
UIView *spview = self.superview;
while (spview)
{
if([spview isKindOfClass:[UITableViewCell class]])
{
UITableViewCell *ownerCell = (UITableViewCell *)spview;
 
if((ownerCell.highlighted || ownerCell.selected) && ownerCell.selectionStyle != UITableViewCellEditingStyleNone)
badgeColor = [UIColor whiteColor];
 
break;
}
 
spview = spview.superview;
}
 
 
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, [badgeColor CGColor]);
CGContextBeginPath(context);
CGFloat radius = self.bounds.size.height / 2.0;
CGContextAddArc(context, radius, radius, radius, M_PI/2 , 3*M_PI/2, NO);
CGContextAddArc(context, self.bounds.size.width - radius, radius, radius, 3*M_PI/2, M_PI/2, NO);
CGContextClosePath(context);
CGContextFillPath(context);
CGContextRestoreGState(context);
 
CGContextSetBlendMode(context, kCGBlendModeClear);
 
CGSize textSize = CGSizeMake(0, 0);
if(self.text)
textSize = [self.text sizeWithFont:self.font];
CGRect textBounds = CGRectMake(round((self.bounds.size.width-textSize.width)/2),
round((self.bounds.size.height-textSize.height)/2),
textSize.width, textSize.height);
[self.text drawInRect:textBounds withFont:self.font];
}
 


The change is this:
if((ownerCell.highlighted || ownerCell.selected) && ownerCell.selectionStyle != UITableViewCellEditingStyleNone)

Re: UIColor doesn't conform to copy protocol 1 year, 1 month ago #4

You're right again Oscar, thanks a lot for all the feedback!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
Time to create page: 0.90 seconds