Adjust ChatRoom cells

This commit is contained in:
Yann Diorcet 2012-07-18 18:03:08 +02:00
parent 4d42d182c1
commit 2163aac96d
3 changed files with 41 additions and 40 deletions

View file

@ -238,7 +238,6 @@
<string key="NSFrame">{{250, 0}, {70, 59}}</string>
<reference key="NSSuperview" ref="833509359"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<object class="IBUIAccessibilityConfiguration" key="IBUIAccessibilityConfiguration">
@ -303,6 +302,7 @@
<bool key="IBUIAdjustsFontSizeToFit">YES</bool>
<float key="IBUIMinimumFontSize">17</float>
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
<int key="IBUIAutocapitalizationType">2</int>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIFontDescription" key="IBUIFontDescription">

View file

@ -32,8 +32,11 @@
@synthesize dateLabel;
@synthesize chat;
static const CGFloat CELL_MIN_HEIGHT = 65.0f;
static const CGFloat CELL_MESSAGE_MAX_WIDTH = 280.0f;
static const CGFloat CELL_MIN_HEIGHT = 40.0f;
static const CGFloat CELL_MIN_WIDTH = 150.0f;
static const CGFloat CELL_MAX_WIDTH = 320.0f;
static const CGFloat CELL_MESSAGE_X_MARGIN = 26.0f;
static const CGFloat CELL_MESSAGE_Y_MARGIN = 33.0f;
static const CGFloat CELL_FONT_SIZE = 17.0f;
static UIFont *CELL_FONT = nil;
@ -115,53 +118,52 @@ static UIFont *CELL_FONT = nil;
}
- (void)resizeContent {
// Resize content
{
CGRect frame = [contentView frame];
frame.origin.x = 0.0f;
frame.origin.y = 0.0f;
frame.size = [self frame].size;
[ contentView setFrame:frame];
}
if(chat != nil) {
CGPoint center = [contentView center];
if(![[chat direction] intValue]) { // Inverted
// Resize Content
CGRect contentFrame = [contentView frame];
contentFrame.size = [UIChatRoomCell viewSize:[chat message]];
if([[chat direction] intValue]) { // Inverted
contentFrame.origin.x = 0.0f;
contentFrame.origin.y = 0.0f;
} else {
contentFrame.origin.x = CELL_MAX_WIDTH - contentFrame.size.width;
contentFrame.origin.y = 0.0f;
}
[contentView setFrame:contentFrame];
CGRect messageFrame = [messageView frame];
messageFrame.origin.y = ([contentView frame].size.height - messageFrame.size.height)/2;
if([[chat direction] intValue]) { // Inverted
[backgroundImage setImage:[TUNinePatchCache imageOfSize:[backgroundImage bounds].size
forNinePatchNamed:@"chat_bubble_incoming"]];
center.y += 6;
messageFrame.origin.y += 5;
} else {
[backgroundImage setImage:[TUNinePatchCache imageOfSize:[backgroundImage bounds].size
forNinePatchNamed:@"chat_bubble_outgoing"]];
center.y -= 6;
messageFrame.origin.y -= 5;
}
[messageView setCenter:center];
}
// Resize messageView
{
CGRect frame = [messageView frame];
frame.size.height = [UIChatRoomCell messageHeight:[chat message]] + 10;
[messageView setFrame:frame];
[messageView setFrame:messageFrame];
}
}
+ (CGFloat)messageHeight:(NSString*)message {
+ (CGSize)viewSize:(NSString*)message {
if(CELL_FONT == nil) {
CELL_FONT = [UIFont systemFontOfSize:CELL_FONT_SIZE];
}
CGSize messageSize = [message sizeWithFont: CELL_FONT
constrainedToSize: CGSizeMake(CELL_MESSAGE_MAX_WIDTH, 10000.0f)
constrainedToSize: CGSizeMake(CELL_MAX_WIDTH - CELL_MESSAGE_X_MARGIN, 10000.0f)
lineBreakMode: UILineBreakModeTailTruncation];
return messageSize.height;
messageSize.height += CELL_MESSAGE_Y_MARGIN;
if(messageSize.height < CELL_MIN_HEIGHT)
messageSize.height = CELL_MIN_HEIGHT;
messageSize.width += CELL_MESSAGE_X_MARGIN;
if(messageSize.width < CELL_MIN_WIDTH)
messageSize.width = CELL_MIN_WIDTH;
return messageSize;
}
+ (CGFloat)height:(ChatModel*)chat {
CGFloat height = [UIChatRoomCell messageHeight:[chat message]];
height += 40;
if(height < CELL_MIN_HEIGHT)
height = CELL_MIN_HEIGHT;
return height;
return [UIChatRoomCell viewSize:[chat message]].height;
}

View file

@ -40,7 +40,7 @@
<object class="IBUIImageView" id="340144998">
<reference key="NSNextResponder" ref="579600281"/>
<int key="NSvFlags">274</int>
<string key="NSFrame">{{10, 10}, {300, 120}}</string>
<string key="NSFrame">{{5, 5}, {310, 130}}</string>
<reference key="NSSuperview" ref="579600281"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="456806949"/>
@ -59,7 +59,7 @@
<object class="IBUILabel" id="281972462">
<reference key="NSNextResponder" ref="456806949"/>
<int key="NSvFlags">274</int>
<string key="NSFrameSize">{280, 90}</string>
<string key="NSFrameSize">{294, 107}</string>
<reference key="NSSuperview" ref="456806949"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="859609488"/>
@ -92,7 +92,7 @@
<object class="IBUIButton" id="859609488">
<reference key="NSNextResponder" ref="456806949"/>
<int key="NSvFlags">289</int>
<string key="NSFrame">{{236, 0}, {44, 44}}</string>
<string key="NSFrame">{{250, 0}, {44, 44}}</string>
<reference key="NSSuperview" ref="456806949"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="504194589"/>
@ -131,10 +131,9 @@
<object class="IBUILabel" id="504194589">
<reference key="NSNextResponder" ref="456806949"/>
<int key="NSvFlags">265</int>
<string key="NSFrame">{{0, 90}, {280, 10}}</string>
<string key="NSFrame">{{14, 107}, {280, 7}}</string>
<reference key="NSSuperview" ref="456806949"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
@ -149,16 +148,16 @@
<int key="IBUITextAlignment">2</int>
<object class="IBUIFontDescription" key="IBUIFontDescription">
<int key="type">1</int>
<double key="pointSize">12</double>
<double key="pointSize">10</double>
</object>
<object class="NSFont" key="IBUIFont">
<string key="NSName">Helvetica</string>
<double key="NSSize">12</double>
<double key="NSSize">10</double>
<int key="NSfFlags">16</int>
</object>
</object>
</array>
<string key="NSFrame">{{20, 20}, {280, 100}}</string>
<string key="NSFrame">{{13, 13}, {294, 114}}</string>
<reference key="NSSuperview" ref="579600281"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="281972462"/>