diff --git a/example/UIBubbleTableViewExample.xcodeproj/project.pbxproj b/example/UIBubbleTableViewExample.xcodeproj/project.pbxproj index 0726282..4a39ea2 100644 --- a/example/UIBubbleTableViewExample.xcodeproj/project.pbxproj +++ b/example/UIBubbleTableViewExample.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 76ED208715BF09E300E186D3 /* UIBubbleTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 76ED208615BF09E300E186D3 /* UIBubbleTableView.m */; }; 76ED208B15BF0BB100E186D3 /* NSBubbleData.m in Sources */ = {isa = PBXBuildFile; fileRef = 76ED208A15BF0BB100E186D3 /* NSBubbleData.m */; }; 76ED209415BF29EE00E186D3 /* UIBubbleTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 76ED209315BF29EE00E186D3 /* UIBubbleTableViewCell.m */; }; + 9508E66816556D54000C5B04 /* image_frame@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9508E66716556D54000C5B04 /* image_frame@2x.png */; }; C83B107915DE43180067DADE /* bubbleMine.png in Resources */ = {isa = PBXBuildFile; fileRef = C83B107115DE43180067DADE /* bubbleMine.png */; }; C83B107A15DE43180067DADE /* bubbleMine@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C83B107215DE43180067DADE /* bubbleMine@2x.png */; }; C83B107B15DE43180067DADE /* bubbleSomeone.png in Resources */ = {isa = PBXBuildFile; fileRef = C83B107315DE43180067DADE /* bubbleSomeone.png */; }; @@ -59,6 +60,7 @@ 76ED208A15BF0BB100E186D3 /* NSBubbleData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NSBubbleData.m; path = ../../src/NSBubbleData.m; sourceTree = ""; }; 76ED209215BF29EE00E186D3 /* UIBubbleTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UIBubbleTableViewCell.h; path = ../../src/UIBubbleTableViewCell.h; sourceTree = ""; }; 76ED209315BF29EE00E186D3 /* UIBubbleTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UIBubbleTableViewCell.m; path = ../../src/UIBubbleTableViewCell.m; sourceTree = ""; }; + 9508E66716556D54000C5B04 /* image_frame@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "image_frame@2x.png"; sourceTree = ""; }; C83B107115DE43180067DADE /* bubbleMine.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bubbleMine.png; sourceTree = ""; }; C83B107215DE43180067DADE /* bubbleMine@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "bubbleMine@2x.png"; sourceTree = ""; }; C83B107315DE43180067DADE /* bubbleSomeone.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bubbleSomeone.png; sourceTree = ""; }; @@ -162,6 +164,7 @@ C83B107015DE43180067DADE /* images */ = { isa = PBXGroup; children = ( + 9508E66716556D54000C5B04 /* image_frame@2x.png */, C83B107115DE43180067DADE /* bubbleMine.png */, C83B107215DE43180067DADE /* bubbleMine@2x.png */, C83B107315DE43180067DADE /* bubbleSomeone.png */, @@ -238,6 +241,7 @@ C83B107F15DE43180067DADE /* typingSomeone.png in Resources */, C83B108015DE43180067DADE /* typingSomeone@2x.png in Resources */, 76687AFF162203AF00707588 /* halloween.jpg in Resources */, + 9508E66816556D54000C5B04 /* image_frame@2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/images/image_frame@2x.png b/images/image_frame@2x.png new file mode 100644 index 0000000..0dea435 Binary files /dev/null and b/images/image_frame@2x.png differ diff --git a/src/NSBubbleData.h b/src/NSBubbleData.h index 0b3f583..a4b8610 100644 --- a/src/NSBubbleData.h +++ b/src/NSBubbleData.h @@ -22,9 +22,12 @@ typedef enum _NSBubbleType @property (readonly, nonatomic) NSBubbleType type; @property (readonly, nonatomic, strong) UIView *view; @property (readonly, nonatomic) UIEdgeInsets insets; +@property (nonatomic, strong) NSObject *customField; - (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type; +- (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type withFont:(UIFont*)customFont withFontColor:(UIColor*)color; + (id)dataWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type; ++ (id)dataWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type withFont:(UIFont*)customFont withFontColor:(UIColor*)color; - (id)initWithImage:(UIImage *)image date:(NSDate *)date type:(NSBubbleType)type; + (id)dataWithImage:(UIImage *)image date:(NSDate *)date type:(NSBubbleType)type; - (id)initWithView:(UIView *)view date:(NSDate *)date type:(NSBubbleType)type insets:(UIEdgeInsets)insets; diff --git a/src/NSBubbleData.m b/src/NSBubbleData.m index 621fb82..80d2d47 100644 --- a/src/NSBubbleData.m +++ b/src/NSBubbleData.m @@ -18,6 +18,7 @@ @implementation NSBubbleData @synthesize type = _type; @synthesize view = _view; @synthesize insets = _insets; +@synthesize customField = _customField; #pragma mark - Lifecycle @@ -38,24 +39,39 @@ - (void)dealloc const UIEdgeInsets textInsetsSomeone = {5, 15, 11, 10}; + (id)dataWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type +{ + return [self dataWithText:text date:date type:type withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]] withFontColor:[UIColor grayColor]]; +} + + ++ (id)dataWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type withFont:(UIFont*)customFont withFontColor:(UIColor*)customColor + { #if !__has_feature(objc_arc) - return [[[NSBubbleData alloc] initWithText:text date:date type:type] autorelease]; + return [[[NSBubbleData alloc] initWithText:text date:date type:type withFont:customFont withFontColor:customColor] autorelease]; #else - return [[NSBubbleData alloc] initWithText:text date:date type:type]; -#endif + return [[NSBubbleData alloc] initWithText:text date:date type:type withFont:customFont withFontColor:customColor]; +#endif } -- (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type +- (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type withFont:(UIFont*)customFont withFontColor:(UIColor*)customColor { - UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]]; - CGSize size = [(text ? text : @"") sizeWithFont:font constrainedToSize:CGSizeMake(220, 9999) lineBreakMode:UILineBreakModeWordWrap]; + if (customFont == nil) { + customFont = [UIFont systemFontOfSize:[UIFont systemFontSize]]; + } + + if (customColor == nil) { + customColor = [UIColor grayColor]; + } + + CGSize size = [(text ? text : @"") sizeWithFont:customFont constrainedToSize:CGSizeMake(220, 9999) lineBreakMode:NSLineBreakByWordWrapping]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)]; label.numberOfLines = 0; - label.lineBreakMode = UILineBreakModeWordWrap; + label.lineBreakMode = NSLineBreakByWordWrapping; label.text = (text ? text : @""); - label.font = font; + label.font = customFont; + label.textColor = customColor; label.backgroundColor = [UIColor clearColor]; #if !__has_feature(objc_arc) @@ -64,6 +80,13 @@ - (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type UIEdgeInsets insets = (type == BubbleTypeMine ? textInsetsMine : textInsetsSomeone); return [self initWithView:label date:date type:type insets:insets]; + +} + +- (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type +{ + UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]]; + return [self initWithText:text date:date type:type withFont:font withFontColor:[UIColor grayColor]]; } #pragma mark - Image bubble diff --git a/src/UIBubbleHeaderTableViewCell.h b/src/UIBubbleHeaderTableViewCell.h index f7beccf..e1262c8 100644 --- a/src/UIBubbleHeaderTableViewCell.h +++ b/src/UIBubbleHeaderTableViewCell.h @@ -14,4 +14,6 @@ @property (nonatomic, strong) NSDate *date; +-(void)setLabelFont:(UIFont*)customFont withFontColor:(UIColor*)customColor; + @end diff --git a/src/UIBubbleHeaderTableViewCell.m b/src/UIBubbleHeaderTableViewCell.m index 330e825..7d8ae45 100644 --- a/src/UIBubbleHeaderTableViewCell.m +++ b/src/UIBubbleHeaderTableViewCell.m @@ -42,14 +42,20 @@ - (void)setDate:(NSDate *)value self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, [UIBubbleHeaderTableViewCell height])]; self.label.text = text; self.label.font = [UIFont boldSystemFontOfSize:12]; - self.label.textAlignment = UITextAlignmentCenter; + self.label.textAlignment = NSTextAlignmentCenter; self.label.shadowOffset = CGSizeMake(0, 1); - self.label.shadowColor = [UIColor whiteColor]; - self.label.textColor = [UIColor darkGrayColor]; + self.label.shadowColor = [UIColor darkGrayColor]; + self.label.textColor = [UIColor whiteColor]; self.label.backgroundColor = [UIColor clearColor]; [self addSubview:self.label]; } - +-(void)setLabelFont:(UIFont*)customFont withFontColor:(UIColor*)customColor +{ + + if (customFont != nil) self.label.font = customFont; + if (customColor != nil) self.label.textColor = customColor; + +} @end diff --git a/src/UIBubbleTableView.h b/src/UIBubbleTableView.h index 51263ea..929d3b3 100644 --- a/src/UIBubbleTableView.h +++ b/src/UIBubbleTableView.h @@ -24,6 +24,11 @@ typedef enum _NSBubbleTypingType @property (nonatomic, assign) id bubbleDataSource; @property (nonatomic) NSTimeInterval snapInterval; +@property (nonatomic, strong) UIFont *customFont; +@property (nonatomic, strong) UIColor *customFontColor; @property (nonatomic) NSBubbleTypingType typingBubble; +@property (nonatomic) BOOL scrollOnActivity; + +-(void)scrollToBottomAnimated:(BOOL)animated; @end diff --git a/src/UIBubbleTableView.m b/src/UIBubbleTableView.m index f189f3a..a791f9d 100644 --- a/src/UIBubbleTableView.m +++ b/src/UIBubbleTableView.m @@ -25,6 +25,8 @@ @implementation UIBubbleTableView @synthesize snapInterval = _snapInterval; @synthesize bubbleSection = _bubbleSection; @synthesize typingBubble = _typingBubble; +@synthesize customFont = _customFont; +@synthesize customFontColor = _customFontColor; #pragma mark - Initializators @@ -147,6 +149,12 @@ - (void)reloadData } [super reloadData]; + + if(self.scrollOnActivity) + { + [self scrollToBottomAnimated:NO]; + } + } #pragma mark - UITableViewDelegate implementation @@ -208,6 +216,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N if (cell == nil) cell = [[UIBubbleHeaderTableViewCell alloc] init]; cell.date = data.date; + [cell setLabelFont:_customFont withFontColor:_customFontColor]; return cell; } @@ -221,4 +230,24 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N return cell; } + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (indexPath.row == 0) return; + + NSBubbleData *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 1]; + [self.bubbleDataSource didSelectNSBubbleDataCell:data]; +} + + +-(void)scrollToBottomAnimated:(BOOL)animated; +{ + NSInteger sectionCount = [self numberOfSections]; + NSInteger rowCount = [self numberOfRowsInSection:sectionCount - 1]; + + NSIndexPath* scrollTo = [NSIndexPath indexPathForRow:rowCount-1 inSection:sectionCount - 1]; + [self scrollToRowAtIndexPath:scrollTo atScrollPosition:UITableViewScrollPositionTop animated:animated]; +} + + @end diff --git a/src/UIBubbleTableViewCell.m b/src/UIBubbleTableViewCell.m index 64ba822..05a9d20 100644 --- a/src/UIBubbleTableViewCell.m +++ b/src/UIBubbleTableViewCell.m @@ -74,7 +74,26 @@ - (void) setupInternalData [self.customView removeFromSuperview]; self.customView = self.data.view; + + if ([self.customView isKindOfClass:[UIImageView class]]) + { + UIImage* imageBorderImg = [[UIImage imageNamed:@"image_frame.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:24]; + UIImageView* whiteBorderView = [[UIImageView alloc] initWithImage:imageBorderImg]; + int borderX = x; + if (borderX >0) { + borderX+=10; + } + else { + borderX+=2; + } + whiteBorderView.frame = CGRectMake(borderX+self.data.insets.left - self.data.insets.right, self.data.insets.top - self.data.insets.bottom+4, width + self.data.insets.left + self.data.insets.right-8, height + self.data.insets.top + self.data.insets.bottom-2); + + [self.contentView addSubview:whiteBorderView]; + + } + self.customView.frame = CGRectMake(x + self.data.insets.left, y + self.data.insets.top, width, height); + [self.contentView addSubview:self.customView]; if (type == BubbleTypeSomeoneElse) diff --git a/src/UIBubbleTableViewDataSource.h b/src/UIBubbleTableViewDataSource.h index 01194e7..6a98c14 100644 --- a/src/UIBubbleTableViewDataSource.h +++ b/src/UIBubbleTableViewDataSource.h @@ -20,5 +20,6 @@ - (NSInteger)rowsForBubbleTable:(UIBubbleTableView *)tableView; - (NSBubbleData *)bubbleTableView:(UIBubbleTableView *)tableView dataForRow:(NSInteger)row; +- (void)didSelectNSBubbleDataCell:(NSBubbleData *)dataCell; @end