Skip to content

Commit

Permalink
Support editing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
digdog committed Jun 12, 2010
1 parent c3d436c commit 24bd988
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions DDBadgeViewCell.m
Expand Up @@ -84,30 +84,38 @@ - (void)drawRect:(CGRect)rect {
currentBadgeColor = [UIColor whiteColor];
}
}

CGSize badgeTextSize = [self.cell.badgeText sizeWithFont:[UIFont boldSystemFontOfSize:13.]];
CGRect badgeViewFrame = CGRectInset(CGRectIntegral(CGRectMake(rect.size.width - badgeTextSize.width - 20, (rect.size.height - badgeTextSize.height) / 2, badgeTextSize.width, badgeTextSize.height)), -7, -2);

CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, currentBadgeColor.CGColor);
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, badgeViewFrame.origin.x + badgeViewFrame.size.width - badgeViewFrame.size.height / 2, badgeViewFrame.origin.y + badgeViewFrame.size.height / 2, badgeViewFrame.size.height / 2, M_PI / 2, M_PI * 3 / 2, YES);
CGPathAddArc(path, NULL, badgeViewFrame.origin.x + badgeViewFrame.size.height / 2, badgeViewFrame.origin.y + badgeViewFrame.size.height / 2, badgeViewFrame.size.height / 2, M_PI * 3 / 2, M_PI / 2, YES);
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathFill);
CFRelease(path);
CGContextRestoreGState(context);

CGContextSaveGState(context);
CGContextSetBlendMode(context, kCGBlendModeClear);
[self.cell.badgeText drawInRect:CGRectInset(badgeViewFrame, 7, 2) withFont:[UIFont boldSystemFontOfSize:13.]];
CGContextRestoreGState(context);

[currentSummaryColor set];
[self.cell.summary drawInRect:CGRectMake(10., 10., badgeViewFrame.origin.x - 15., 22.) withFont:[UIFont boldSystemFontOfSize:18.] lineBreakMode:UILineBreakModeTailTruncation];

[currentDetailColor set];
[self.cell.detail drawInRect:CGRectMake(10., 32., badgeViewFrame.origin.x - 15., 18.) withFont:[UIFont systemFontOfSize:14.] lineBreakMode:UILineBreakModeTailTruncation];
if (self.cell.isEditing) {
[currentSummaryColor set];
[self.cell.summary drawAtPoint:CGPointMake(10, 10) forWidth:rect.size.width withFont:[UIFont boldSystemFontOfSize:18.] lineBreakMode:UILineBreakModeTailTruncation];

[currentDetailColor set];
[self.cell.detail drawAtPoint:CGPointMake(10, 32) forWidth:rect.size.width withFont:[UIFont systemFontOfSize:14.] lineBreakMode:UILineBreakModeTailTruncation];
} else {
CGSize badgeTextSize = [self.cell.badgeText sizeWithFont:[UIFont boldSystemFontOfSize:13.]];
CGRect badgeViewFrame = CGRectIntegral(CGRectMake(rect.size.width - badgeTextSize.width - 24, (rect.size.height - badgeTextSize.height - 4) / 2, badgeTextSize.width + 14, badgeTextSize.height + 4));

CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, currentBadgeColor.CGColor);
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, badgeViewFrame.origin.x + badgeViewFrame.size.width - badgeViewFrame.size.height / 2, badgeViewFrame.origin.y + badgeViewFrame.size.height / 2, badgeViewFrame.size.height / 2, M_PI / 2, M_PI * 3 / 2, YES);
CGPathAddArc(path, NULL, badgeViewFrame.origin.x + badgeViewFrame.size.height / 2, badgeViewFrame.origin.y + badgeViewFrame.size.height / 2, badgeViewFrame.size.height / 2, M_PI * 3 / 2, M_PI / 2, YES);
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathFill);
CFRelease(path);
CGContextRestoreGState(context);

CGContextSaveGState(context);
CGContextSetBlendMode(context, kCGBlendModeClear);
[self.cell.badgeText drawInRect:CGRectInset(badgeViewFrame, 7, 2) withFont:[UIFont boldSystemFontOfSize:13.]];
CGContextRestoreGState(context);

[currentSummaryColor set];
[self.cell.summary drawAtPoint:CGPointMake(10, 10) forWidth:(rect.size.width - badgeViewFrame.size.width - 24) withFont:[UIFont boldSystemFontOfSize:18.] lineBreakMode:UILineBreakModeTailTruncation];

[currentDetailColor set];
[self.cell.detail drawAtPoint:CGPointMake(10, 32) forWidth:(rect.size.width - badgeViewFrame.size.width - 24) withFont:[UIFont systemFontOfSize:14.] lineBreakMode:UILineBreakModeTailTruncation];
}
}

@end
Expand Down Expand Up @@ -153,6 +161,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
badgeView_ = [[DDBadgeView alloc] initWithFrame:self.contentView.bounds cell:self];
badgeView_.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
badgeView_.contentMode = UIViewContentModeRedraw;
badgeView_.contentStretch = CGRectMake(1., 0., 0., 0.);
[self.contentView addSubview:badgeView_];
}
return self;
Expand All @@ -178,10 +187,8 @@ - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

[super setEditing:editing animated:animated];

[UIView beginAnimations:@"hiddenAnimation" context:NULL];
self.badgeView.hidden = editing;
[UIView commitAnimations];

[self.badgeView setNeedsDisplay];
}

@end

0 comments on commit 24bd988

Please sign in to comment.