diff --git a/example/UIBubbleTableViewExample.xcodeproj/project.pbxproj b/example/UIBubbleTableViewExample.xcodeproj/project.pbxproj index eb707a1..0726282 100644 --- a/example/UIBubbleTableViewExample.xcodeproj/project.pbxproj +++ b/example/UIBubbleTableViewExample.xcodeproj/project.pbxproj @@ -7,7 +7,9 @@ objects = { /* Begin PBXBuildFile section */ - 760D63931621BF100026FA70 /* fields.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 760D63921621BF100026FA70 /* fields.jpg */; }; + 76687AFD1622039C00707588 /* UIBubbleTypingTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 76687AFC1622039C00707588 /* UIBubbleTypingTableViewCell.m */; }; + 76687AFF162203AF00707588 /* halloween.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 76687AFE162203AF00707588 /* halloween.jpg */; }; + 76D097CC1621F0E000C17816 /* UIBubbleHeaderTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 76D097CB1621F0E000C17816 /* UIBubbleHeaderTableViewCell.m */; }; 76ED206315BF096C00E186D3 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 76ED206215BF096C00E186D3 /* UIKit.framework */; }; 76ED206515BF096C00E186D3 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 76ED206415BF096C00E186D3 /* Foundation.framework */; }; 76ED206715BF096C00E186D3 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 76ED206615BF096C00E186D3 /* CoreGraphics.framework */; }; @@ -18,9 +20,7 @@ 76ED207915BF096C00E186D3 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 76ED207715BF096C00E186D3 /* ViewController.xib */; }; 76ED208715BF09E300E186D3 /* UIBubbleTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 76ED208615BF09E300E186D3 /* UIBubbleTableView.m */; }; 76ED208B15BF0BB100E186D3 /* NSBubbleData.m in Sources */ = {isa = PBXBuildFile; fileRef = 76ED208A15BF0BB100E186D3 /* NSBubbleData.m */; }; - 76ED209115BF263600E186D3 /* NSBubbleDataInternal.m in Sources */ = {isa = PBXBuildFile; fileRef = 76ED209015BF263600E186D3 /* NSBubbleDataInternal.m */; }; 76ED209415BF29EE00E186D3 /* UIBubbleTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 76ED209315BF29EE00E186D3 /* UIBubbleTableViewCell.m */; }; - 76ED209615BF2A1400E186D3 /* UIBubbleTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 76ED209515BF2A1400E186D3 /* UIBubbleTableViewCell.xib */; }; 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 */; }; @@ -34,7 +34,11 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 760D63921621BF100026FA70 /* fields.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = fields.jpg; sourceTree = SOURCE_ROOT; }; + 76687AFB1622039C00707588 /* UIBubbleTypingTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UIBubbleTypingTableViewCell.h; path = ../../src/UIBubbleTypingTableViewCell.h; sourceTree = ""; }; + 76687AFC1622039C00707588 /* UIBubbleTypingTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UIBubbleTypingTableViewCell.m; path = ../../src/UIBubbleTypingTableViewCell.m; sourceTree = ""; }; + 76687AFE162203AF00707588 /* halloween.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = halloween.jpg; sourceTree = SOURCE_ROOT; }; + 76D097CA1621F0E000C17816 /* UIBubbleHeaderTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UIBubbleHeaderTableViewCell.h; path = ../../src/UIBubbleHeaderTableViewCell.h; sourceTree = ""; }; + 76D097CB1621F0E000C17816 /* UIBubbleHeaderTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UIBubbleHeaderTableViewCell.m; path = ../../src/UIBubbleHeaderTableViewCell.m; sourceTree = ""; }; 76ED205E15BF096C00E186D3 /* UIBubbleTableViewExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UIBubbleTableViewExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 76ED206215BF096C00E186D3 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 76ED206415BF096C00E186D3 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -53,11 +57,8 @@ 76ED208815BF0B4400E186D3 /* UIBubbleTableViewDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = UIBubbleTableViewDataSource.h; path = ../../src/UIBubbleTableViewDataSource.h; sourceTree = ""; }; 76ED208915BF0BB100E186D3 /* NSBubbleData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NSBubbleData.h; path = ../../src/NSBubbleData.h; sourceTree = ""; }; 76ED208A15BF0BB100E186D3 /* NSBubbleData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NSBubbleData.m; path = ../../src/NSBubbleData.m; sourceTree = ""; }; - 76ED208F15BF263600E186D3 /* NSBubbleDataInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NSBubbleDataInternal.h; path = ../../src/NSBubbleDataInternal.h; sourceTree = ""; }; - 76ED209015BF263600E186D3 /* NSBubbleDataInternal.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NSBubbleDataInternal.m; path = ../../src/NSBubbleDataInternal.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 = ""; }; - 76ED209515BF2A1400E186D3 /* UIBubbleTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = UIBubbleTableViewCell.xib; path = ../../src/UIBubbleTableViewCell.xib; 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 = ""; }; @@ -129,7 +130,7 @@ 76ED206915BF096C00E186D3 /* Supporting Files */ = { isa = PBXGroup; children = ( - 760D63921621BF100026FA70 /* fields.jpg */, + 76687AFE162203AF00707588 /* halloween.jpg */, C86D4FFD15BFEBC1003F161E /* icon_114.png */, C86D4FFB15BFEBBF003F161E /* icon_57.png */, 76ED206A15BF096C00E186D3 /* UIBubbleTableViewExample-Info.plist */, @@ -145,13 +146,14 @@ children = ( 76ED208915BF0BB100E186D3 /* NSBubbleData.h */, 76ED208A15BF0BB100E186D3 /* NSBubbleData.m */, - 76ED208F15BF263600E186D3 /* NSBubbleDataInternal.h */, - 76ED209015BF263600E186D3 /* NSBubbleDataInternal.m */, 76ED208515BF09E300E186D3 /* UIBubbleTableView.h */, 76ED208615BF09E300E186D3 /* UIBubbleTableView.m */, 76ED209215BF29EE00E186D3 /* UIBubbleTableViewCell.h */, 76ED209315BF29EE00E186D3 /* UIBubbleTableViewCell.m */, - 76ED209515BF2A1400E186D3 /* UIBubbleTableViewCell.xib */, + 76D097CA1621F0E000C17816 /* UIBubbleHeaderTableViewCell.h */, + 76D097CB1621F0E000C17816 /* UIBubbleHeaderTableViewCell.m */, + 76687AFB1622039C00707588 /* UIBubbleTypingTableViewCell.h */, + 76687AFC1622039C00707588 /* UIBubbleTypingTableViewCell.m */, 76ED208815BF0B4400E186D3 /* UIBubbleTableViewDataSource.h */, ); name = src; @@ -225,7 +227,6 @@ files = ( 76ED206D15BF096C00E186D3 /* InfoPlist.strings in Resources */, 76ED207915BF096C00E186D3 /* ViewController.xib in Resources */, - 76ED209615BF2A1400E186D3 /* UIBubbleTableViewCell.xib in Resources */, C86D4FFC15BFEBBF003F161E /* icon_57.png in Resources */, C86D4FFE15BFEBC1003F161E /* icon_114.png in Resources */, C83B107915DE43180067DADE /* bubbleMine.png in Resources */, @@ -236,7 +237,7 @@ C83B107E15DE43180067DADE /* typingMine@2x.png in Resources */, C83B107F15DE43180067DADE /* typingSomeone.png in Resources */, C83B108015DE43180067DADE /* typingSomeone@2x.png in Resources */, - 760D63931621BF100026FA70 /* fields.jpg in Resources */, + 76687AFF162203AF00707588 /* halloween.jpg in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -252,8 +253,9 @@ 76ED207615BF096C00E186D3 /* ViewController.m in Sources */, 76ED208715BF09E300E186D3 /* UIBubbleTableView.m in Sources */, 76ED208B15BF0BB100E186D3 /* NSBubbleData.m in Sources */, - 76ED209115BF263600E186D3 /* NSBubbleDataInternal.m in Sources */, 76ED209415BF29EE00E186D3 /* UIBubbleTableViewCell.m in Sources */, + 76D097CC1621F0E000C17816 /* UIBubbleHeaderTableViewCell.m in Sources */, + 76687AFD1622039C00707588 /* UIBubbleTypingTableViewCell.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/example/UIBubbleTableViewExample/AppDelegate.h b/example/UIBubbleTableViewExample/AppDelegate.h index 78d034c..58568a3 100644 --- a/example/UIBubbleTableViewExample/AppDelegate.h +++ b/example/UIBubbleTableViewExample/AppDelegate.h @@ -2,9 +2,6 @@ // AppDelegate.h // // Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// // Project home page: http://alexbarinov.github.com/UIBubbleTableView/ // // This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. diff --git a/example/UIBubbleTableViewExample/AppDelegate.m b/example/UIBubbleTableViewExample/AppDelegate.m index 6754aaf..485e87f 100644 --- a/example/UIBubbleTableViewExample/AppDelegate.m +++ b/example/UIBubbleTableViewExample/AppDelegate.m @@ -2,9 +2,6 @@ // AppDelegate.m // // Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// // Project home page: http://alexbarinov.github.com/UIBubbleTableView/ // // This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. diff --git a/example/UIBubbleTableViewExample/ViewController.h b/example/UIBubbleTableViewExample/ViewController.h index fd9fb14..c57446e 100644 --- a/example/UIBubbleTableViewExample/ViewController.h +++ b/example/UIBubbleTableViewExample/ViewController.h @@ -2,9 +2,6 @@ // ViewController.h // // Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// // Project home page: http://alexbarinov.github.com/UIBubbleTableView/ // // This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. diff --git a/example/UIBubbleTableViewExample/ViewController.m b/example/UIBubbleTableViewExample/ViewController.m index 9d7774a..387476c 100644 --- a/example/UIBubbleTableViewExample/ViewController.m +++ b/example/UIBubbleTableViewExample/ViewController.m @@ -2,15 +2,17 @@ // ViewController.m // // Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// // Project home page: http://alexbarinov.github.com/UIBubbleTableView/ // // This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. // To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ // +// +// Halloween image used in this example by Petr Kratochvil released into public domain +// http://www.publicdomainpictures.net/view-image.php?image=9806&picture=halloween-autumn-theme +// + #import "ViewController.h" #import "UIBubbleTableView.h" #import "UIBubbleTableViewDataSource.h" @@ -23,12 +25,9 @@ - (void)viewDidLoad [super viewDidLoad]; bubbleData = [[NSMutableArray alloc] initWithObjects: - [NSBubbleData dataWithText:@"Marge, there's something that I want to ask you, but I'm afraid, because if you say no, it will destroy me and make me a criminal." andDate:[NSDate dateWithTimeIntervalSinceNow:-300] andType:BubbleTypeMine], - [NSBubbleData dataWithText:@"Well, I haven't said no to you yet, have I?" andDate:[NSDate dateWithTimeIntervalSinceNow:-280] andType:BubbleTypeSomeoneElse], - [NSBubbleData dataWithText:@"Marge... Oh, damn it." andDate:[NSDate dateWithTimeIntervalSinceNow:0] andType:BubbleTypeMine], - [NSBubbleData dataWithText:@"What's wrong?" andDate:[NSDate dateWithTimeIntervalSinceNow:300] andType:BubbleTypeSomeoneElse], - [NSBubbleData dataWithText:@"Ohn I wrote down what I wanted to say on a card.." andDate:[NSDate dateWithTimeIntervalSinceNow:395] andType:BubbleTypeMine], - [NSBubbleData dataWithText:@"The stupid thing must have fallen out of my pocket." andDate:[NSDate dateWithTimeIntervalSinceNow:400] andType:BubbleTypeMine], + [NSBubbleData dataWithText:@"Hey, halloween is soon" date:[NSDate dateWithTimeIntervalSinceNow:-300] type:BubbleTypeSomeoneElse], + [NSBubbleData dataWithImage:[UIImage imageNamed:@"halloween.jpg"] date:[NSDate dateWithTimeIntervalSinceNow:-290] type:BubbleTypeSomeoneElse], + [NSBubbleData dataWithText:@"Wow.. Really cool picture out there. iPhone 5 has really nice camera, yeah?" date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine], nil]; bubbleTable.bubbleDataSource = self; diff --git a/example/UIBubbleTableViewExample/main.m b/example/UIBubbleTableViewExample/main.m index 0d66541..fa12e90 100644 --- a/example/UIBubbleTableViewExample/main.m +++ b/example/UIBubbleTableViewExample/main.m @@ -1,9 +1,11 @@ // // main.m -// UIBubbleTableViewExample // -// Created by Alex Barinov on 7/24/12. -// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// Created by Alex Barinov +// Project home page: http://alexbarinov.github.com/UIBubbleTableView/ +// +// This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. +// To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ // #import diff --git a/example/halloween.jpg b/example/halloween.jpg new file mode 100644 index 0000000..8c82496 Binary files /dev/null and b/example/halloween.jpg differ diff --git a/src/NSBubbleData.h b/src/NSBubbleData.h index 9baca4d..0b3f583 100644 --- a/src/NSBubbleData.h +++ b/src/NSBubbleData.h @@ -2,9 +2,6 @@ // NSBubbleData.h // // Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// // Project home page: http://alexbarinov.github.com/UIBubbleTableView/ // // This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. @@ -23,12 +20,14 @@ typedef enum _NSBubbleType @property (readonly, nonatomic, strong) NSDate *date; @property (readonly, nonatomic) NSBubbleType type; -@property (readonly, nonatomic, strong) NSString *text; @property (readonly, nonatomic, strong) UIView *view; +@property (readonly, nonatomic) UIEdgeInsets insets; -- (id)initWithText:(NSString *)text andDate:(NSDate *)date andType:(NSBubbleType)type; -+ (id)dataWithText:(NSString *)text andDate:(NSDate *)date andType:(NSBubbleType)type; -- (id)initWithView:(UIView *)view andDate:(NSDate *)date andType:(NSBubbleType)type; -+ (id)dataWithView:(UIView *)view andDate:(NSDate *)date andType:(NSBubbleType)type; +- (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type; ++ (id)dataWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type; +- (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; ++ (id)dataWithView:(UIView *)view date:(NSDate *)date type:(NSBubbleType)type insets:(UIEdgeInsets)insets; @end diff --git a/src/NSBubbleData.m b/src/NSBubbleData.m index 8724e32..621fb82 100644 --- a/src/NSBubbleData.m +++ b/src/NSBubbleData.m @@ -2,9 +2,6 @@ // NSBubbleData.m // // Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// // Project home page: http://alexbarinov.github.com/UIBubbleTableView/ // // This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. @@ -15,46 +12,106 @@ @implementation NSBubbleData +#pragma mark - Properties + @synthesize date = _date; @synthesize type = _type; -@synthesize text = _text; @synthesize view = _view; +@synthesize insets = _insets; + +#pragma mark - Lifecycle + +#if !__has_feature(objc_arc) +- (void)dealloc +{ + [_date release]; + _date = nil; + [_view release]; + _view = nil; + [super dealloc]; +} +#endif + +#pragma mark - Text bubble -+ (id)dataWithText:(NSString *)text andDate:(NSDate *)date andType:(NSBubbleType)type +const UIEdgeInsets textInsetsMine = {5, 10, 11, 17}; +const UIEdgeInsets textInsetsSomeone = {5, 15, 11, 10}; + ++ (id)dataWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type { #if !__has_feature(objc_arc) - return [[[NSBubbleData alloc] initWithText:text andDate:date andType:type] autorelease]; + return [[[NSBubbleData alloc] initWithText:text date:date type:type] autorelease]; #else - return [[NSBubbleData alloc] initWithText:text andDate:date andType:type]; + return [[NSBubbleData alloc] initWithText:text date:date type:type]; #endif } -- (id)initWithText:(NSString *)text andDate:(NSDate *)date andType:(NSBubbleType)initType +- (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type { - self = [super init]; - if (self) - { + UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]]; + CGSize size = [(text ? text : @"") sizeWithFont:font constrainedToSize:CGSizeMake(220, 9999) lineBreakMode:UILineBreakModeWordWrap]; + + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)]; + label.numberOfLines = 0; + label.lineBreakMode = UILineBreakModeWordWrap; + label.text = (text ? text : @""); + label.font = font; + label.backgroundColor = [UIColor clearColor]; + #if !__has_feature(objc_arc) - _text = [text retain]; - _date = [date retain]; -#else - _text = text; - _date = date; + [label autorelease]; #endif + + UIEdgeInsets insets = (type == BubbleTypeMine ? textInsetsMine : textInsetsSomeone); + return [self initWithView:label date:date type:type insets:insets]; +} - if (!_text || [_text isEqualToString:@""]) _text = @" "; - - _type = initType; +#pragma mark - Image bubble + +const UIEdgeInsets imageInsetsMine = {11, 13, 16, 22}; +const UIEdgeInsets imageInsetsSomeone = {11, 18, 16, 14}; + ++ (id)dataWithImage:(UIImage *)image date:(NSDate *)date type:(NSBubbleType)type +{ +#if !__has_feature(objc_arc) + return [[[NSBubbleData alloc] initWithImage:image date:date type:type] autorelease]; +#else + return [[NSBubbleData alloc] initWithImage:image date:date type:type]; +#endif +} + +- (id)initWithImage:(UIImage *)image date:(NSDate *)date type:(NSBubbleType)type +{ + CGSize size = image.size; + if (size.width > 220) + { + size.height /= (size.width / 220); + size.width = 220; } - return self; + + UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)]; + imageView.image = image; + +#if !__has_feature(objc_arc) + [imageView autorelease]; +#endif + + UIEdgeInsets insets = (type == BubbleTypeMine ? imageInsetsMine : imageInsetsSomeone); + return [self initWithView:imageView date:date type:type insets:insets]; } -+ (id)dataWithView:(UIView *)view andDate:(NSDate *)date andType:(NSBubbleType)type +#pragma mark - Custom view bubble + ++ (id)dataWithView:(UIView *)view date:(NSDate *)date type:(NSBubbleType)type insets:(UIEdgeInsets)insets { - return [[[NSBubbleData alloc] initWithView:view andDate:date andType:type] autorelease]; +#if !__has_feature(objc_arc) + return [[[NSBubbleData alloc] initWithView:view date:date type:type insets:insets] autorelease]; +#else + return [[NSBubbleData alloc] initWithView:view date:date type:type insets:insets]; +#endif } -- (id)initWithView:(UIView *)view andDate:(NSDate *)date andType:(NSBubbleType)type +- (id)initWithView:(UIView *)view date:(NSDate *)date type:(NSBubbleType)type insets:(UIEdgeInsets)insets { self = [super init]; if (self) @@ -67,21 +124,9 @@ - (id)initWithView:(UIView *)view andDate:(NSDate *)date andType:(NSBubbleType)t _date = date; #endif _type = type; + _insets = insets; } return self; } -#if !__has_feature(objc_arc) -- (void)dealloc -{ - [_date release]; - [_text release]; - _date = nil; - _text = nil; - [_view release]; - _view = nil; - [super dealloc]; -} -#endif - @end diff --git a/src/NSBubbleDataInternal.h b/src/NSBubbleDataInternal.h deleted file mode 100644 index b35f20b..0000000 --- a/src/NSBubbleDataInternal.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// NSBubbleDataInternal.h -// -// Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// -// Project home page: http://alexbarinov.github.com/UIBubbleTableView/ -// -// This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. -// To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ -// - -#import - -@class NSBubbleData; - -typedef enum _NSBubbleDataType -{ - NSBubbleDataTypeNormalBubble = 0, - NSBubbleDataTypeTypingBubble = 1 -} NSBubbleDataType; - -@interface NSBubbleDataInternal : NSObject - -@property (nonatomic, strong) NSBubbleData* data; -@property (nonatomic) NSBubbleDataType type; -@property (nonatomic) float height; -@property (nonatomic) CGSize labelSize; -@property (nonatomic, strong) NSString *header; - -@end diff --git a/src/NSBubbleDataInternal.m b/src/NSBubbleDataInternal.m deleted file mode 100644 index 1943aac..0000000 --- a/src/NSBubbleDataInternal.m +++ /dev/null @@ -1,36 +0,0 @@ -// -// NSBubbleDataInternal.m -// -// Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// -// Project home page: http://alexbarinov.github.com/UIBubbleTableView/ -// -// This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. -// To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ -// - -#import "NSBubbleDataInternal.h" -#import "NSBubbleData.h" - -@implementation NSBubbleDataInternal - -@synthesize data = _data; -@synthesize type = _type; -@synthesize header = _header; -@synthesize height = _height; -@synthesize labelSize = _labelSize; - -#if !__has_feature(objc_arc) -- (void)dealloc -{ - [_data release]; - [_header release]; - _data = nil; - _header = nil; - [super dealloc]; -} -#endif - -@end diff --git a/src/UIBubbleHeaderTableViewCell.h b/src/UIBubbleHeaderTableViewCell.h new file mode 100644 index 0000000..f7beccf --- /dev/null +++ b/src/UIBubbleHeaderTableViewCell.h @@ -0,0 +1,17 @@ +// +// UIBubbleHeaderTableViewCell.h +// UIBubbleTableViewExample +// +// Created by Александр Баринов on 10/7/12. +// Copyright (c) 2012 Stex Group. All rights reserved. +// + +#import + +@interface UIBubbleHeaderTableViewCell : UITableViewCell + ++ (CGFloat)height; + +@property (nonatomic, strong) NSDate *date; + +@end diff --git a/src/UIBubbleHeaderTableViewCell.m b/src/UIBubbleHeaderTableViewCell.m new file mode 100644 index 0000000..330e825 --- /dev/null +++ b/src/UIBubbleHeaderTableViewCell.m @@ -0,0 +1,55 @@ +// +// UIBubbleHeaderTableViewCell.m +// UIBubbleTableViewExample +// +// Created by Александр Баринов on 10/7/12. +// Copyright (c) 2012 Stex Group. All rights reserved. +// + +#import "UIBubbleHeaderTableViewCell.h" + +@interface UIBubbleHeaderTableViewCell () + +@property (nonatomic, retain) UILabel *label; + +@end + +@implementation UIBubbleHeaderTableViewCell + +@synthesize label = _label; +@synthesize date = _date; + ++ (CGFloat)height +{ + return 28.0; +} + +- (void)setDate:(NSDate *)value +{ + NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; + [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; + [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; + NSString *text = [dateFormatter stringFromDate:value]; + [dateFormatter release]; + + if (self.label) + { + self.label.text = text; + return; + } + + self.selectionStyle = UITableViewCellSelectionStyleNone; + 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.shadowOffset = CGSizeMake(0, 1); + self.label.shadowColor = [UIColor whiteColor]; + self.label.textColor = [UIColor darkGrayColor]; + self.label.backgroundColor = [UIColor clearColor]; + [self addSubview:self.label]; +} + + + +@end diff --git a/src/UIBubbleTableView.h b/src/UIBubbleTableView.h index 9016a9d..51263ea 100644 --- a/src/UIBubbleTableView.h +++ b/src/UIBubbleTableView.h @@ -2,9 +2,6 @@ // UIBubbleTableView.h // // Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// // Project home page: http://alexbarinov.github.com/UIBubbleTableView/ // // This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. @@ -24,9 +21,6 @@ typedef enum _NSBubbleTypingType } NSBubbleTypingType; @interface UIBubbleTableView : UITableView -{ - IBOutlet UIBubbleTableViewCell *bubbleCell; -} @property (nonatomic, assign) id bubbleDataSource; @property (nonatomic) NSTimeInterval snapInterval; diff --git a/src/UIBubbleTableView.m b/src/UIBubbleTableView.m index fb3ec24..f189f3a 100644 --- a/src/UIBubbleTableView.m +++ b/src/UIBubbleTableView.m @@ -2,9 +2,6 @@ // UIBubbleTableView.m // // Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// // Project home page: http://alexbarinov.github.com/UIBubbleTableView/ // // This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. @@ -13,11 +10,12 @@ #import "UIBubbleTableView.h" #import "NSBubbleData.h" -#import "NSBubbleDataInternal.h" +#import "UIBubbleHeaderTableViewCell.h" +#import "UIBubbleTypingTableViewCell.h" @interface UIBubbleTableView () -@property (nonatomic, retain) NSMutableDictionary *bubbleDictionary; +@property (nonatomic, retain) NSMutableArray *bubbleSection; @end @@ -25,7 +23,7 @@ @implementation UIBubbleTableView @synthesize bubbleDataSource = _bubbleDataSource; @synthesize snapInterval = _snapInterval; -@synthesize bubbleDictionary = _bubbleDictionary; +@synthesize bubbleSection = _bubbleSection; @synthesize typingBubble = _typingBubble; #pragma mark - Initializators @@ -78,8 +76,8 @@ - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style #if !__has_feature(objc_arc) - (void)dealloc { - [_bubbleDictionary release]; - _bubbleDictionary = nil; + [_bubbleSection release]; + _bubbleSection = nil; _bubbleDataSource = nil; [super dealloc]; } @@ -89,15 +87,18 @@ - (void)dealloc - (void)reloadData { + self.showsVerticalScrollIndicator = NO; + self.showsHorizontalScrollIndicator = NO; + // Cleaning up - self.bubbleDictionary = nil; + self.bubbleSection = nil; // Loading new data int count = 0; #if !__has_feature(objc_arc) - self.bubbleDictionary = [[[NSMutableDictionary alloc] init] autorelease]; + self.bubbleSection = [[[NSMutableArray alloc] init] autorelease]; #else - self.bubbleDictionary = [[NSMutableDictionary alloc] init]; + self.bubbleSection = [[NSMutableArray alloc] init]; #endif if (self.bubbleDataSource && (count = [self.bubbleDataSource rowsForBubbleTable:self]) > 0) @@ -116,83 +117,33 @@ - (void)reloadData } [bubbleData sortUsingComparator:^NSComparisonResult(id obj1, id obj2) - { - - NSBubbleData *bubbleData1 = (NSBubbleData *)obj1; - NSBubbleData *bubbleData2 = (NSBubbleData *)obj2; - - return [bubbleData1.date compare:bubbleData2.date]; - }]; + { + NSBubbleData *bubbleData1 = (NSBubbleData *)obj1; + NSBubbleData *bubbleData2 = (NSBubbleData *)obj2; + + return [bubbleData1.date compare:bubbleData2.date]; + }]; NSDate *last = [NSDate dateWithTimeIntervalSince1970:0]; NSMutableArray *currentSection = nil; - NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; - [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; - for (int i = 0; i < count; i++) { -#if !__has_feature(objc_arc) - NSBubbleDataInternal *dataInternal = [[[NSBubbleDataInternal alloc] init] autorelease]; -#else - NSBubbleDataInternal *dataInternal = [[NSBubbleDataInternal alloc] init]; -#endif - - dataInternal.data = (NSBubbleData *)[bubbleData objectAtIndex:i]; - dataInternal.type = NSBubbleDataTypeNormalBubble; - - // Calculating cell height - CGFloat dataHeight = 0.0; - if (dataInternal.data.text) - { - dataInternal.labelSize = [(dataInternal.data.text ? dataInternal.data.text : @"") sizeWithFont:[UIFont systemFontOfSize:[UIFont systemFontSize]] constrainedToSize:CGSizeMake(220, 9999) lineBreakMode:UILineBreakModeWordWrap]; - dataHeight = dataInternal.labelSize.height; - } - else - dataHeight = CGRectGetHeight(dataInternal.data.view.frame)+12.0 /*cf offsetY in cell. this not really cool implementation all these values*/; - - dataInternal.height = dataHeight + 5 + 11; + NSBubbleData *data = (NSBubbleData *)[bubbleData objectAtIndex:i]; - dataInternal.header = nil; - - if ([dataInternal.data.date timeIntervalSinceDate:last] > self.snapInterval) + if ([data.date timeIntervalSinceDate:last] > self.snapInterval) { #if !__has_feature(objc_arc) currentSection = [[[NSMutableArray alloc] init] autorelease]; #else currentSection = [[NSMutableArray alloc] init]; #endif - [self.bubbleDictionary setObject:currentSection forKey:[NSString stringWithFormat:@"%d", i]]; - dataInternal.header = [dateFormatter stringFromDate:dataInternal.data.date]; - dataInternal.height += 30; + [self.bubbleSection addObject:currentSection]; } - - [currentSection addObject:dataInternal]; - last = dataInternal.data.date; + + [currentSection addObject:data]; + last = data.date; } - -#if !__has_feature(objc_arc) - [dateFormatter release]; -#endif - } - - // Adding the typing bubble at the end of the table - - if (self.typingBubble != NSBubbleTypingTypeNobody) - { -#if !__has_feature(objc_arc) - NSBubbleDataInternal *dataInternal = [[[NSBubbleDataInternal alloc] init] autorelease]; -#else - NSBubbleDataInternal *dataInternal = [[NSBubbleDataInternal alloc] init]; -#endif - - dataInternal.data = nil; - dataInternal.type = NSBubbleDataTypeTypingBubble; - dataInternal.labelSize = CGSizeMake(0, 0); - dataInternal.height = 40; - - [self.bubbleDictionary setObject:[NSMutableArray arrayWithObject:dataInternal] forKey:[NSString stringWithFormat:@"%d", count]]; } [super reloadData]; @@ -204,93 +155,70 @@ - (void)reloadData - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return [[self.bubbleDictionary allKeys] count]; + int result = [self.bubbleSection count]; + if (self.typingBubble != NSBubbleTypingTypeNobody) result++; + return result; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - NSArray *keys = [self.bubbleDictionary allKeys]; - NSArray *sortedArray = [keys sortedArrayUsingComparator:^(id firstObject, id secondObject) { - return [((NSString *)firstObject) compare:((NSString *)secondObject) options:NSNumericSearch]; - }]; - NSString *key = [sortedArray objectAtIndex:section]; - return [[self.bubbleDictionary objectForKey:key] count]; + // This is for now typing bubble + if (section >= [self.bubbleSection count]) return 1; + + return [[self.bubbleSection objectAtIndex:section] count] + 1; } - (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - NSArray *keys = [self.bubbleDictionary allKeys]; - NSArray *sortedArray = [keys sortedArrayUsingComparator:^(id firstObject, id secondObject) { - return [((NSString *)firstObject) compare:((NSString *)secondObject) options:NSNumericSearch]; - }]; - NSString *key = [sortedArray objectAtIndex:indexPath.section]; - NSBubbleDataInternal *dataInternal = ((NSBubbleDataInternal *)[[self.bubbleDictionary objectForKey:key] objectAtIndex:indexPath.row]); - - return dataInternal.height; + // Now typing + if (indexPath.section >= [self.bubbleSection count]) + { + return [UIBubbleTypingTableViewCell height]; + } + + // Header + if (indexPath.row == 0) + { + return [UIBubbleHeaderTableViewCell height]; + } + + NSBubbleData *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 1]; + return data.insets.top + data.view.frame.size.height + data.insets.bottom; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - NSArray *keys = [self.bubbleDictionary allKeys]; - NSArray *sortedArray = [keys sortedArrayUsingComparator:^(id firstObject, id secondObject) { - return [((NSString *)firstObject) compare:((NSString *)secondObject) options:NSNumericSearch]; - }]; - NSString *key = [sortedArray objectAtIndex:indexPath.section]; - - NSBubbleDataInternal *dataInternal = ((NSBubbleDataInternal *)[[self.bubbleDictionary objectForKey:key] objectAtIndex:indexPath.row]); - - if (dataInternal.type == NSBubbleDataTypeNormalBubble) - { - static NSString *cellId = @"tblBubbleCell"; - UIBubbleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; - - if (cell == nil) - { - [[NSBundle mainBundle] loadNibNamed:@"UIBubbleTableViewCell" owner:self options:nil]; - cell = bubbleCell; - } - - cell.dataInternal = dataInternal; + // Now typing + if (indexPath.section >= [self.bubbleSection count]) + { + static NSString *cellId = @"tblBubbleTypingCell"; + UIBubbleTypingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; + + if (cell == nil) cell = [[UIBubbleTypingTableViewCell alloc] init]; + cell.type = self.typingBubble; return cell; } - - if (dataInternal.type == NSBubbleDataTypeTypingBubble) + + // Header with date and time + if (indexPath.row == 0) { - static NSString *cellTypingId = @"tblBubbleTypingCell"; - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellTypingId]; - - if (cell == nil) - { - cell = [[UITableViewCell alloc] init]; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - - UIImage *bubbleImage = nil; - float x = 0; - - if (self.typingBubble == NSBubbleTypingTypeMe) - { - bubbleImage = [UIImage imageNamed:@"typingMine.png"]; - x = cell.frame.size.width - 4 - bubbleImage.size.width; - } - else - { - bubbleImage = [UIImage imageNamed:@"typingSomeone.png"]; - x = 4; - } - - UIImageView *bubbleImageView = [[UIImageView alloc] initWithImage:bubbleImage]; - bubbleImageView.frame = CGRectMake(x, 4, 73, 31); -#if !__has_feature(objc_arc) - [cell addSubview:[bubbleImageView autorelease]]; -#else - [cell addSubview:bubbleImageView]; -#endif - } + static NSString *cellId = @"tblBubbleHeaderCell"; + UIBubbleHeaderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; + NSBubbleData *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:0]; + if (cell == nil) cell = [[UIBubbleHeaderTableViewCell alloc] init]; + cell.date = data.date; return cell; } - return nil; + // Standard bubble + static NSString *cellId = @"tblBubbleCell"; + UIBubbleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; + NSBubbleData *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 1]; + + if (cell == nil) cell = [[UIBubbleTableViewCell alloc] init]; + cell.data = data; + return cell; } @end diff --git a/src/UIBubbleTableViewCell.h b/src/UIBubbleTableViewCell.h index 0e5e2ab..f013d3b 100644 --- a/src/UIBubbleTableViewCell.h +++ b/src/UIBubbleTableViewCell.h @@ -2,26 +2,17 @@ // UIBubbleTableViewCell.h // // Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// // Project home page: http://alexbarinov.github.com/UIBubbleTableView/ // // This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. // To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ // - #import -#import "NSBubbleDataInternal.h" +#import "NSBubbleData.h" @interface UIBubbleTableViewCell : UITableViewCell -{ - IBOutlet UILabel *headerLabel; - IBOutlet UILabel *contentLabel; - IBOutlet UIImageView *bubbleImage; -} -@property (nonatomic, strong) NSBubbleDataInternal *dataInternal; +@property (nonatomic, strong) NSBubbleData *data; @end diff --git a/src/UIBubbleTableViewCell.m b/src/UIBubbleTableViewCell.m index fd80a0b..64ba822 100644 --- a/src/UIBubbleTableViewCell.m +++ b/src/UIBubbleTableViewCell.m @@ -2,28 +2,29 @@ // UIBubbleTableViewCell.m // // Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// // Project home page: http://alexbarinov.github.com/UIBubbleTableView/ // // This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. // To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ // - #import "UIBubbleTableViewCell.h" #import "NSBubbleData.h" @interface UIBubbleTableViewCell () + +@property (nonatomic, retain) UIView *customView; +@property (nonatomic, retain) UIImageView *bubbleImage; + - (void) setupInternalData; -@property (nonatomic, retain) UIView *oldCustomView; + @end @implementation UIBubbleTableViewCell -@synthesize dataInternal = _dataInternal; -@synthesize oldCustomView = _oldCustomView; +@synthesize data = _data; +@synthesize customView = _customView; +@synthesize bubbleImage = _bubbleImage; - (void)setFrame:(CGRect)frame { @@ -34,73 +35,58 @@ - (void)setFrame:(CGRect)frame #if !__has_feature(objc_arc) - (void) dealloc { - [_dataInternal release]; - _dataInternal = nil; - [_oldCustomView release]; - _oldCustomView = nil; + [_data release]; + _data = nil; + [_customView release]; + _customView = nil; [super dealloc]; } #endif -- (void)setDataInternal:(NSBubbleDataInternal *)value +- (void)setDataInternal:(NSBubbleData *)value { #if !__has_feature(objc_arc) [value retain]; - [_dataInternal release]; + [_data release]; #endif - _dataInternal = value; + _data = value; [self setupInternalData]; } - (void) setupInternalData { - if (self.dataInternal.header) - { - headerLabel.hidden = NO; - headerLabel.text = self.dataInternal.header; - } - else + self.selectionStyle = UITableViewCellSelectionStyleNone; + + if (!self.bubbleImage) { - headerLabel.hidden = YES; + self.bubbleImage = [[UIImageView alloc] init]; + [self addSubview:self.bubbleImage]; } - NSBubbleType type = self.dataInternal.data.type; - CGFloat imageOffsetX = 5.0; - CGFloat imageOffsetY = 6.0; + NSBubbleType type = self.data.type; - CGFloat height = self.dataInternal.data.view ? (CGRectGetHeight(self.dataInternal.data.view.frame) + imageOffsetY*2.0) : self.dataInternal.labelSize.height; - CGFloat width = self.dataInternal.data.view ? (CGRectGetWidth(self.dataInternal.data.view.frame) + imageOffsetX*2.0) : self.dataInternal.labelSize.width; + CGFloat width = self.data.view.frame.size.width; + CGFloat height = self.data.view.frame.size.height; - float x = (type == BubbleTypeSomeoneElse) ? 20 : self.frame.size.width - 20 - width; - float y = 5 + (self.dataInternal.header ? 30 : 0); + CGFloat x = (type == BubbleTypeSomeoneElse) ? 0 : self.frame.size.width - width - self.data.insets.left - self.data.insets.right; + CGFloat y = 0; - [self.oldCustomView removeFromSuperview]; - self.oldCustomView = nil; - - if (!self.dataInternal.data.view) - { - contentLabel.hidden = NO; - contentLabel.font = [UIFont systemFontOfSize:[UIFont systemFontSize]]; - contentLabel.frame = CGRectMake(x, y, self.dataInternal.labelSize.width, self.dataInternal.labelSize.height); - contentLabel.text = self.dataInternal.data.text; - } - else - { - contentLabel.hidden = YES; - self.oldCustomView = self.dataInternal.data.view; - [self.contentView addSubview:self.oldCustomView]; - self.oldCustomView.frame = CGRectMake(x+imageOffsetX-1.0, y+imageOffsetY+3.0, CGRectGetWidth(self.oldCustomView.frame), CGRectGetHeight(self.oldCustomView.frame)); - } + [self.customView removeFromSuperview]; + self.customView = self.data.view; + self.customView.frame = CGRectMake(x + self.data.insets.left, y + self.data.insets.top, width, height); + [self.contentView addSubview:self.customView]; + if (type == BubbleTypeSomeoneElse) { - bubbleImage.image = [[UIImage imageNamed:@"bubbleSomeone.png"] stretchableImageWithLeftCapWidth:21 topCapHeight:14]; - bubbleImage.frame = CGRectMake(x - 18, y - 4, width + 30, height + 15); + self.bubbleImage.image = [[UIImage imageNamed:@"bubbleSomeone.png"] stretchableImageWithLeftCapWidth:21 topCapHeight:14]; + } else { - bubbleImage.image = [[UIImage imageNamed:@"bubbleMine.png"] stretchableImageWithLeftCapWidth:15 topCapHeight:14]; - bubbleImage.frame = CGRectMake(x - 9, y - 4, width + 26, height + 15); + self.bubbleImage.image = [[UIImage imageNamed:@"bubbleMine.png"] stretchableImageWithLeftCapWidth:15 topCapHeight:14]; } + + self.bubbleImage.frame = CGRectMake(x, y, width + self.data.insets.left + self.data.insets.right, height + self.data.insets.top + self.data.insets.bottom); } @end diff --git a/src/UIBubbleTableViewCell.xib b/src/UIBubbleTableViewCell.xib deleted file mode 100644 index 1c32863..0000000 --- a/src/UIBubbleTableViewCell.xib +++ /dev/null @@ -1,310 +0,0 @@ - - - - 1296 - 11E53 - 2182 - 1138.47 - 569.00 - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 1179 - - - IBUITableViewCell - IBUIImageView - IBUILabel - IBProxyObject - - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - PluginDependencyRecalculationVersion - - - - - IBFilesOwner - IBCocoaTouchFramework - - - IBFirstResponder - IBCocoaTouchFramework - - - - 292 - - - - 256 - - - - 290 - {{0, 5}, {320, 20}} - - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - - - 3 - MC4zMzMzMzMzMzMzAA - - - 3 - MQA - - - {0, 1} - 0 - 10 - 1 - - 2 - 12 - - - Helvetica-Bold - 12 - 16 - - - - - 292 - {{17, 38}, {75, 41}} - - - - _NS:9 - NO - IBCocoaTouchFramework - - - - 292 - {{100, 29}, {220, 52}} - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - - - 1 - MCAwIDAAA - - - 0 - 10 - 0 - 0 - - 1 - 17 - - - Helvetica - 17 - 16 - - - - {320, 83} - - - - _NS:11 - - 3 - MCAwAA - - NO - YES - 4 - YES - IBCocoaTouchFramework - - - {320, 84} - - - - _NS:9 - IBCocoaTouchFramework - 0 - - tblBubbleCell - - - - - - - - bubbleCell - - - - 6 - - - - headerLabel - - - - 5 - - - - contentLabel - - - - 8 - - - - bubbleImage - - - - 11 - - - - - - 0 - - - - - - -1 - - - File's Owner - - - -2 - - - - - 2 - - - - - - - - - - 3 - - - - - 4 - - - - - 9 - - - - - - - UIBubbleTableView - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIBubbleTableViewCell - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - - - 11 - - - - - UIBubbleTableView - UITableView - - bubbleCell - UIBubbleTableViewCell - - - bubbleCell - - bubbleCell - UIBubbleTableViewCell - - - - IBProjectSource - ./Classes/UIBubbleTableView.h - - - - UIBubbleTableViewCell - UITableViewCell - - UIImageView - UILabel - UILabel - - - - bubbleImage - UIImageView - - - contentLabel - UILabel - - - headerLabel - UILabel - - - - IBProjectSource - ./Classes/UIBubbleTableViewCell.h - - - - - 0 - IBCocoaTouchFramework - - com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS - - - YES - 3 - 1179 - - diff --git a/src/UIBubbleTableViewDataSource.h b/src/UIBubbleTableViewDataSource.h index e5fc192..01194e7 100644 --- a/src/UIBubbleTableViewDataSource.h +++ b/src/UIBubbleTableViewDataSource.h @@ -2,9 +2,6 @@ // UIBubbleTableViewDataSource.h // // Created by Alex Barinov -// StexGroup, LLC -// http://www.stexgroup.com -// // Project home page: http://alexbarinov.github.com/UIBubbleTableView/ // // This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. diff --git a/src/UIBubbleTypingTableViewCell.h b/src/UIBubbleTypingTableViewCell.h new file mode 100644 index 0000000..eb45e38 --- /dev/null +++ b/src/UIBubbleTypingTableViewCell.h @@ -0,0 +1,19 @@ +// +// UIBubbleTypingTableCell.h +// UIBubbleTableViewExample +// +// Created by Александр Баринов on 10/7/12. +// Copyright (c) 2012 Stex Group. All rights reserved. +// + +#import +#import "UIBubbleTableView.h" + + +@interface UIBubbleTypingTableViewCell : UITableViewCell + ++ (CGFloat)height; + +@property (nonatomic) NSBubbleTypingType type; + +@end diff --git a/src/UIBubbleTypingTableViewCell.m b/src/UIBubbleTypingTableViewCell.m new file mode 100644 index 0000000..9092a28 --- /dev/null +++ b/src/UIBubbleTypingTableViewCell.m @@ -0,0 +1,55 @@ +// +// UIBubbleTypingTableCell.m +// UIBubbleTableViewExample +// +// Created by Александр Баринов on 10/7/12. +// Copyright (c) 2012 Stex Group. All rights reserved. +// + +#import "UIBubbleTypingTableViewCell.h" + +@interface UIBubbleTypingTableViewCell () + +@property (nonatomic, retain) UIImageView *typingImageView; + +@end + +@implementation UIBubbleTypingTableViewCell + +@synthesize type = _type; +@synthesize typingImageView; + ++ (CGFloat)height +{ + return 40.0; +} + +- (void)setType:(NSBubbleTypingType)value +{ + if (!self.typingImageView) + { + self.typingImageView = [[UIImageView alloc] init]; + [self addSubview:self.typingImageView]; + } + + self.selectionStyle = UITableViewCellSelectionStyleNone; + + UIImage *bubbleImage = nil; + CGFloat x = 0; + + if (value == NSBubbleTypingTypeMe) + { + bubbleImage = [UIImage imageNamed:@"typingMine.png"]; + x = self.frame.size.width - bubbleImage.size.width; + } + else + { + bubbleImage = [UIImage imageNamed:@"typingSomeone.png"]; + x = 0; + } + + self.typingImageView.image = bubbleImage; + self.typingImageView.frame = CGRectMake(x, 4, 73, 31); +} + +@end