Skip to content
Browse files

BadgeX var for moving the badge.

  • Loading branch information...
1 parent cb383de commit 4cbdb84307d6662e3809ad5ac48b8c645cb38e58 @penso committed Feb 27, 2012
Showing with 45 additions and 34 deletions.
  1. +20 −4 DDBadgeViewCell.h
  2. +25 −30 DDBadgeViewCell.m
View
24 DDBadgeViewCell.h
@@ -27,24 +27,40 @@
#import <UIKit/UIKit.h>
-@class DDBadgeView;
+@class DDBadgeViewCell;
+@interface DDBadgeView : UIView {
+
+@private
+ DDBadgeViewCell *cell_;
+}
+
+@property (nonatomic, strong) DDBadgeViewCell *cell;
+
+- (id)initWithFrame:(CGRect)frame cell:(DDBadgeViewCell *)newCell;
+@end
+
+
@interface DDBadgeViewCell : UITableViewCell {
-@private
+@protected
DDBadgeView * badgeView_;
NSString * summary_;
NSString * detail_;
NSString * badgeText_;
UIColor * badgeColor_;
UIColor * badgeHighlightedColor_;
+
+ CGFloat badgeX_;
}
@property (nonatomic, copy) NSString * summary;
@property (nonatomic, copy) NSString * detail;
@property (nonatomic, copy) NSString * badgeText;
-@property (nonatomic, retain) UIColor * badgeColor;
-@property (nonatomic, retain) UIColor * badgeHighlightedColor;
+@property (nonatomic, strong) UIColor * badgeColor;
+@property (nonatomic, strong) UIColor * badgeHighlightedColor;
+@property (nonatomic, strong) DDBadgeView * badgeView;
+@property (nonatomic) CGFloat badgeX;
@end
View
55 DDBadgeViewCell.m
@@ -31,16 +31,6 @@
#pragma mark -
#pragma mark DDBadgeView declaration
-@interface DDBadgeView : UIView {
-
-@private
- DDBadgeViewCell *cell_;
-}
-
-@property (nonatomic, assign) DDBadgeViewCell *cell;
-
-- (id)initWithFrame:(CGRect)frame cell:(DDBadgeViewCell *)newCell;
-@end
#pragma mark -
#pragma mark DDBadgeView implementation
@@ -94,8 +84,20 @@ - (void)drawRect:(CGRect)rect {
[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));
-
+
+ CGRect badgeViewFrame = CGRectIntegral(CGRectMake(rect.size.width - badgeTextSize.width - 24,
+ (rect.size.height - badgeTextSize.height - 4) / 2,
+ badgeTextSize.width + 14,
+ badgeTextSize.height + 4));
+
+ if (self.cell.badgeX > 0) {
+ badgeViewFrame = CGRectIntegral(CGRectMake(self.cell.badgeX - badgeTextSize.width,
+ (rect.size.height - badgeTextSize.height - 4) / 2,
+ badgeTextSize.width + 14,
+ badgeTextSize.height + 4));
+ }
+
+
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, currentBadgeColor.CGColor);
CGMutablePathRef path = CGPathCreateMutable();
@@ -124,10 +126,6 @@ - (void)drawRect:(CGRect)rect {
#pragma mark -
#pragma mark DDBadgeViewCell private
-@interface DDBadgeViewCell ()
-@property (nonatomic, retain) DDBadgeView * badgeView;
-@end
-
#pragma mark -
#pragma mark DDBadgeViewCell implementation
@@ -139,23 +137,11 @@ @implementation DDBadgeViewCell
@synthesize badgeText = badgeText_;
@synthesize badgeColor = badgeColor_;
@synthesize badgeHighlightedColor = badgeHighlightedColor_;
+@synthesize badgeX=badgeX;
#pragma mark -
#pragma mark init & dealloc
-- (void)dealloc {
-
- [badgeView_ release], badgeView_ = nil;
-
- [summary_ release], summary_ = nil;
- [detail_ release], detail_ = nil;
- [badgeText_ release], badgeText_ = nil;
- [badgeColor_ release], badgeColor_ = nil;
- [badgeHighlightedColor_ release], badgeHighlightedColor_ = nil;
-
- [super dealloc];
-}
-
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
@@ -164,13 +150,22 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
badgeView_.contentMode = UIViewContentModeRedraw;
badgeView_.contentStretch = CGRectMake(1., 0., 0., 0.);
[self.contentView addSubview:badgeView_];
+ badgeX_ = -1;
}
return self;
}
+- (void)awakeFromNib {
+ 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_];
+ badgeX_ = -1;
+}
+
#pragma mark -
#pragma mark accessors
-
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];

0 comments on commit 4cbdb84

Please sign in to comment.
Something went wrong with that request. Please try again.