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

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions example/UIBubbleTableViewExample/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//

#import <UIKit/UIKit.h>
#import "UIBubbleTableViewDataSource.h"
#import "BTVBubbleTableViewDataSource.h"

@interface ViewController : UIViewController <UIBubbleTableViewDataSource>
@interface ViewController : UIViewController <BTVBubbleTableViewDataSource>

@end
20 changes: 10 additions & 10 deletions example/UIBubbleTableViewExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
//

#import "ViewController.h"
#import "UIBubbleTableView.h"
#import "UIBubbleTableViewDataSource.h"
#import "NSBubbleData.h"
#import "BTVBubbleTableView.h"
#import "BTVBubbleTableViewDataSource.h"
#import "BTVBubbleData.h"

@interface ViewController ()
{
IBOutlet UIBubbleTableView *bubbleTable;
IBOutlet BTVBubbleTableView *bubbleTable;
IBOutlet UIView *textInputView;
IBOutlet UITextField *textField;

Expand All @@ -36,13 +36,13 @@ - (void)viewDidLoad
{
[super viewDidLoad];

NSBubbleData *heyBubble = [NSBubbleData dataWithText:@"Hey, halloween is soon" date:[NSDate dateWithTimeIntervalSinceNow:-300] type:BubbleTypeSomeoneElse];
BTVBubbleData *heyBubble = [BTVBubbleData dataWithText:@"Hey, halloween is soon" date:[NSDate dateWithTimeIntervalSinceNow:-300] type:BubbleTypeSomeoneElse];
heyBubble.avatar = [UIImage imageNamed:@"avatar1.png"];

NSBubbleData *photoBubble = [NSBubbleData dataWithImage:[UIImage imageNamed:@"halloween.jpg"] date:[NSDate dateWithTimeIntervalSinceNow:-290] type:BubbleTypeSomeoneElse];
BTVBubbleData *photoBubble = [BTVBubbleData dataWithImage:[UIImage imageNamed:@"halloween.jpg"] date:[NSDate dateWithTimeIntervalSinceNow:-290] type:BubbleTypeSomeoneElse];
photoBubble.avatar = [UIImage imageNamed:@"avatar1.png"];

NSBubbleData *replyBubble = [NSBubbleData dataWithText:@"Wow.. Really cool picture out there. iPhone 5 has really nice camera, yeah?" date:[NSDate dateWithTimeIntervalSinceNow:-5] type:BubbleTypeMine];
BTVBubbleData *replyBubble = [BTVBubbleData dataWithText:@"Wow.. Really cool picture out there. iPhone 5 has really nice camera, yeah?" date:[NSDate dateWithTimeIntervalSinceNow:-5] type:BubbleTypeMine];
replyBubble.avatar = nil;

bubbleData = [[NSMutableArray alloc] initWithObjects:heyBubble, photoBubble, replyBubble, nil];
Expand Down Expand Up @@ -82,12 +82,12 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface

#pragma mark - UIBubbleTableViewDataSource implementation

- (NSInteger)rowsForBubbleTable:(UIBubbleTableView *)tableView
- (NSInteger)numberOfRowsForBubbleTable:(BTVBubbleTableView *)tableView
{
return [bubbleData count];
}

- (NSBubbleData *)bubbleTableView:(UIBubbleTableView *)tableView dataForRow:(NSInteger)row
- (BTVBubbleData *)bubbleTableView:(BTVBubbleTableView *)tableView dataForRow:(NSInteger)row
{
return [bubbleData objectAtIndex:row];
}
Expand Down Expand Up @@ -134,7 +134,7 @@ - (IBAction)sayPressed:(id)sender
{
bubbleTable.typingBubble = NSBubbleTypingTypeNobody;

NSBubbleData *sayBubble = [NSBubbleData dataWithText:textField.text date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine];
BTVBubbleData *sayBubble = [BTVBubbleData dataWithText:textField.text date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine];
[bubbleData addObject:sayBubble];
[bubbleTable reloadData];

Expand Down
22 changes: 8 additions & 14 deletions example/UIBubbleTableViewExample/en.lproj/ViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1536</int>
<string key="IBDocument.SystemVersion">11E53</string>
<string key="IBDocument.InterfaceBuilderVersion">2840</string>
<string key="IBDocument.AppKitVersion">1138.47</string>
<string key="IBDocument.HIToolboxVersion">569.00</string>
<string key="IBDocument.SystemVersion">12C60</string>
<string key="IBDocument.InterfaceBuilderVersion">2844</string>
<string key="IBDocument.AppKitVersion">1187.34</string>
<string key="IBDocument.HIToolboxVersion">625.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">1926</string>
<string key="NS.object.0">1930</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBProxyObject</string>
Expand All @@ -34,15 +34,14 @@
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="774585933">
<reference key="NSNextResponder"/>
<nil key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUITableView" id="329568878">
<reference key="NSNextResponder" ref="774585933"/>
<int key="NSvFlags">274</int>
<string key="NSFrameSize">{320, 425}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="416510560"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor" id="13708287">
Expand All @@ -68,7 +67,6 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{2, 3}, {235, 30}}</string>
<reference key="NSSuperview" ref="416510560"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="163443158"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
Expand Down Expand Up @@ -104,7 +102,6 @@
<int key="NSvFlags">292</int>
<string key="NSFrame">{{245, 2}, {73, 32}}</string>
<reference key="NSSuperview" ref="416510560"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
Expand Down Expand Up @@ -134,7 +131,6 @@
</array>
<string key="NSFrame">{{0, 425}, {320, 35}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="117433678"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
Expand All @@ -145,8 +141,6 @@
</object>
</array>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="329568878"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
Expand Down Expand Up @@ -265,7 +259,7 @@
<string key="13.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="14.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="8.CustomClassName">UIBubbleTableView</string>
<string key="8.CustomClassName">BTVBubbleTableView</string>
<string key="8.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
Expand Down Expand Up @@ -343,6 +337,6 @@
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">1926</string>
<string key="IBCocoaTouchPluginVersion">1930</string>
</data>
</archive>
37 changes: 37 additions & 0 deletions src/BTVBubbleData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// NSBubbleData.h
//
// 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 <Foundation/Foundation.h>

typedef enum _BTVBubbleType
{
BubbleTypeMine = 0,
BubbleTypeSomeoneElse = 1,
BubbleTypeInfo = 2
} BTVBubbleType;

@interface BTVBubbleData : NSObject

@property (readonly, nonatomic, strong) NSDate *date;
@property (readonly, nonatomic) BTVBubbleType type;
@property (readonly, nonatomic, strong) UIView *view;
@property (readonly, nonatomic) UIEdgeInsets insets;
@property (nonatomic, strong) UIImage *avatar;
@property (strong, nonatomic) NSString *text;
@property (strong, nonatomic) NSString *userLabel;

- (id)initWithText:(NSString *)text date:(NSDate *)date type:(BTVBubbleType)type;
+ (id)dataWithText:(NSString *)text date:(NSDate *)date type:(BTVBubbleType)type;
- (id)initWithImage:(UIImage *)image date:(NSDate *)date type:(BTVBubbleType)type;
+ (id)dataWithImage:(UIImage *)image date:(NSDate *)date type:(BTVBubbleType)type;
- (id)initWithView:(UIView *)view date:(NSDate *)date type:(BTVBubbleType)type insets:(UIEdgeInsets)insets;
+ (id)dataWithView:(UIView *)view date:(NSDate *)date type:(BTVBubbleType)type insets:(UIEdgeInsets)insets;

@end
33 changes: 18 additions & 15 deletions src/NSBubbleData.m → src/BTVBubbleData.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/
//

#import "NSBubbleData.h"
#import "BTVBubbleData.h"
#import <QuartzCore/QuartzCore.h>

@implementation NSBubbleData
@implementation BTVBubbleData

#pragma mark - Properties

Expand Down Expand Up @@ -42,50 +42,53 @@ - (void)dealloc
const UIEdgeInsets textInsetsMine = {5, 10, 11, 17};
const UIEdgeInsets textInsetsSomeone = {5, 15, 11, 10};

+ (id)dataWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type
+ (id)dataWithText:(NSString *)text date:(NSDate *)date type:(BTVBubbleType)type
{
#if !__has_feature(objc_arc)
return [[[NSBubbleData alloc] initWithText:text date:date type:type] autorelease];
return [[[BTVBubbleData alloc] initWithText:text date:date type:type] autorelease];
#else
return [[NSBubbleData alloc] initWithText:text date:date type:type];
#endif
}

- (id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type
- (id)initWithText:(NSString *)text date:(NSDate *)date type:(BTVBubbleType)type
{
UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
CGSize size = [(text ? text : @"") sizeWithFont:font constrainedToSize:CGSizeMake(220, 9999) lineBreakMode:UILineBreakModeWordWrap];
CGSize size = [(text ? text : @"") sizeWithFont:font 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.backgroundColor = [UIColor clearColor];

#if !__has_feature(objc_arc)
[label autorelease];
#endif

UIEdgeInsets insets = (type == BubbleTypeMine ? textInsetsMine : textInsetsSomeone);
return [self initWithView:label date:date type:type insets:insets];
if((self = [self initWithView:label date:date type:type insets:insets]))
{
self.text = text;
}
return self;
}

#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
+ (id)dataWithImage:(UIImage *)image date:(NSDate *)date type:(BTVBubbleType)type
{
#if !__has_feature(objc_arc)
return [[[NSBubbleData alloc] initWithImage:image date:date type:type] autorelease];
return [[[BTVBubbleData 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
- (id)initWithImage:(UIImage *)image date:(NSDate *)date type:(BTVBubbleType)type
{
CGSize size = image.size;
if (size.width > 220)
Expand All @@ -110,16 +113,16 @@ - (id)initWithImage:(UIImage *)image date:(NSDate *)date type:(NSBubbleType)type

#pragma mark - Custom view bubble

+ (id)dataWithView:(UIView *)view date:(NSDate *)date type:(NSBubbleType)type insets:(UIEdgeInsets)insets
+ (id)dataWithView:(UIView *)view date:(NSDate *)date type:(BTVBubbleType)type insets:(UIEdgeInsets)insets
{
#if !__has_feature(objc_arc)
return [[[NSBubbleData alloc] initWithView:view date:date type:type insets:insets] autorelease];
return [[[BTVBubbleData 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 date:(NSDate *)date type:(NSBubbleType)type insets:(UIEdgeInsets)insets
- (id)initWithView:(UIView *)view date:(NSDate *)date type:(BTVBubbleType)type insets:(UIEdgeInsets)insets
{
self = [super init];
if (self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

#import <UIKit/UIKit.h>

@interface UIBubbleHeaderTableViewCell : UITableViewCell
@interface BTVBubbleHeaderTableViewCell : UITableViewCell

+ (CGFloat)height;

@property (nonatomic, strong) NSDate *date;
@property (strong, nonatomic) NSString *info;

@end
70 changes: 70 additions & 0 deletions src/BTVBubbleHeaderTableViewCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// UIBubbleHeaderTableViewCell.m
// UIBubbleTableViewExample
//
// Created by Александр Баринов on 10/7/12.
// Copyright (c) 2012 Stex Group. All rights reserved.
//

#import "BTVBubbleHeaderTableViewCell.h"

@interface BTVBubbleHeaderTableViewCell ()

@property (nonatomic, retain) UILabel *label;

@end

@implementation BTVBubbleHeaderTableViewCell

@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.selectionStyle = UITableViewCellSelectionStyleNone;
self.label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, [BTVBubbleHeaderTableViewCell height])] autorelease];
self.label.font = [UIFont boldSystemFontOfSize:12];
self.label.textAlignment = NSTextAlignmentCenter;
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];
}

self.label.text = text;
}

-(void)setInfo:(NSString *)info
{
if(!self.label)
{
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, [BTVBubbleHeaderTableViewCell height])] autorelease];
self.label.font = [UIFont boldSystemFontOfSize:12];
self.label.textAlignment = NSTextAlignmentCenter;
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];
}
self.label.text = info;
_info = info;
}


@end
Loading