Skip to content
This repository was archived by the owner on Mar 9, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions example/UIBubbleTableViewExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 9508E66716556D54000C5B04 /* [email protected] */; };
C83B107915DE43180067DADE /* bubbleMine.png in Resources */ = {isa = PBXBuildFile; fileRef = C83B107115DE43180067DADE /* bubbleMine.png */; };
C83B107A15DE43180067DADE /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = C83B107215DE43180067DADE /* [email protected] */; };
C83B107B15DE43180067DADE /* bubbleSomeone.png in Resources */ = {isa = PBXBuildFile; fileRef = C83B107315DE43180067DADE /* bubbleSomeone.png */; };
Expand Down Expand Up @@ -59,6 +60,7 @@
76ED208A15BF0BB100E186D3 /* NSBubbleData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NSBubbleData.m; path = ../../src/NSBubbleData.m; sourceTree = "<group>"; };
76ED209215BF29EE00E186D3 /* UIBubbleTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UIBubbleTableViewCell.h; path = ../../src/UIBubbleTableViewCell.h; sourceTree = "<group>"; };
76ED209315BF29EE00E186D3 /* UIBubbleTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UIBubbleTableViewCell.m; path = ../../src/UIBubbleTableViewCell.m; sourceTree = "<group>"; };
9508E66716556D54000C5B04 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
C83B107115DE43180067DADE /* bubbleMine.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bubbleMine.png; sourceTree = "<group>"; };
C83B107215DE43180067DADE /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
C83B107315DE43180067DADE /* bubbleSomeone.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bubbleSomeone.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -162,6 +164,7 @@
C83B107015DE43180067DADE /* images */ = {
isa = PBXGroup;
children = (
9508E66716556D54000C5B04 /* [email protected] */,
C83B107115DE43180067DADE /* bubbleMine.png */,
C83B107215DE43180067DADE /* [email protected] */,
C83B107315DE43180067DADE /* bubbleSomeone.png */,
Expand Down Expand Up @@ -238,6 +241,7 @@
C83B107F15DE43180067DADE /* typingSomeone.png in Resources */,
C83B108015DE43180067DADE /* [email protected] in Resources */,
76687AFF162203AF00707588 /* halloween.jpg in Resources */,
9508E66816556D54000C5B04 /* [email protected] in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file added images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/NSBubbleData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 31 additions & 8 deletions src/NSBubbleData.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ @implementation NSBubbleData
@synthesize type = _type;
@synthesize view = _view;
@synthesize insets = _insets;
@synthesize customField = _customField;

#pragma mark - Lifecycle

Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/UIBubbleHeaderTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

@property (nonatomic, strong) NSDate *date;

-(void)setLabelFont:(UIFont*)customFont withFontColor:(UIColor*)customColor;

@end
14 changes: 10 additions & 4 deletions src/UIBubbleHeaderTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/UIBubbleTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ typedef enum _NSBubbleTypingType

@property (nonatomic, assign) id<UIBubbleTableViewDataSource> 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
29 changes: 29 additions & 0 deletions src/UIBubbleTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ @implementation UIBubbleTableView
@synthesize snapInterval = _snapInterval;
@synthesize bubbleSection = _bubbleSection;
@synthesize typingBubble = _typingBubble;
@synthesize customFont = _customFont;
@synthesize customFontColor = _customFontColor;

#pragma mark - Initializators

Expand Down Expand Up @@ -147,6 +149,12 @@ - (void)reloadData
}

[super reloadData];

if(self.scrollOnActivity)
{
[self scrollToBottomAnimated:NO];
}

}

#pragma mark - UITableViewDelegate implementation
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
19 changes: 19 additions & 0 deletions src/UIBubbleTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/UIBubbleTableViewDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@

- (NSInteger)rowsForBubbleTable:(UIBubbleTableView *)tableView;
- (NSBubbleData *)bubbleTableView:(UIBubbleTableView *)tableView dataForRow:(NSInteger)row;
- (void)didSelectNSBubbleDataCell:(NSBubbleData *)dataCell;

@end