Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

187 lines (144 sloc) 6.487 kb
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import "Three20UI/TTTableSubtitleItemCell.h"
// UI
#import "Three20UI/TTImageView.h"
#import "Three20UI/TTTableSubtitleItem.h"
#import "Three20UI/UIViewAdditions.h"
#import "Three20Style/UIFontAdditions.h"
// Style
#import "Three20Style/TTGlobalStyle.h"
#import "Three20Style/TTDefaultStyleSheet.h"
// Core
#import "Three20Core/TTCorePreprocessorMacros.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation TTTableSubtitleItemCell
///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)identifier {
self = [super initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:identifier];
if (self) {
self.textLabel.font = TTSTYLEVAR(tableFont);
self.textLabel.textColor = TTSTYLEVAR(textColor);
self.textLabel.highlightedTextColor = TTSTYLEVAR(highlightedTextColor);
self.textLabel.backgroundColor = TTSTYLEVAR(backgroundTextColor);
self.textLabel.textAlignment = UITextAlignmentLeft;
self.textLabel.lineBreakMode = UILineBreakModeTailTruncation;
self.textLabel.adjustsFontSizeToFitWidth = YES;
self.detailTextLabel.font = TTSTYLEVAR(font);
self.detailTextLabel.textColor = TTSTYLEVAR(tableSubTextColor);
self.detailTextLabel.highlightedTextColor = TTSTYLEVAR(highlightedTextColor);
self.detailTextLabel.backgroundColor = TTSTYLEVAR(backgroundTextColor);
self.detailTextLabel.textAlignment = UITextAlignmentLeft;
self.detailTextLabel.contentMode = UIViewContentModeTop;
self.detailTextLabel.lineBreakMode = UILineBreakModeTailTruncation;
self.detailTextLabel.numberOfLines = kTableMessageTextLineCount;
}
return self;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc {
TT_RELEASE_SAFELY(_imageView2);
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark TTTableViewCell class public
///////////////////////////////////////////////////////////////////////////////////////////////////
+ (CGFloat)tableView:(UITableView*)tableView rowHeightForObject:(id)object {
TTTableSubtitleItem* item = object;
CGFloat height = TTSTYLEVAR(tableFont).ttLineHeight + kTableCellVPadding*2;
if (item.subtitle) {
height += TTSTYLEVAR(font).ttLineHeight;
}
return height;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark UIView
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)prepareForReuse {
[super prepareForReuse];
[_imageView2 unsetImage];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat height = self.contentView.height;
CGFloat width = self.contentView.width - (height + kTableCellSmallMargin);
CGFloat left = 0.0f;
if (_imageView2) {
_imageView2.frame = CGRectMake(0, 0, height, height);
left = _imageView2.right + kTableCellSmallMargin;
} else {
left = kTableCellHPadding;
}
if (self.detailTextLabel.text.length) {
CGFloat textHeight = self.textLabel.font.ttLineHeight;
CGFloat subtitleHeight = self.detailTextLabel.font.ttLineHeight;
CGFloat paddingY = floor((height - (textHeight + subtitleHeight))/2);
self.textLabel.frame = CGRectMake(left, paddingY, width, textHeight);
self.detailTextLabel.frame = CGRectMake(left, self.textLabel.bottom, width, subtitleHeight);
} else {
self.textLabel.frame = CGRectMake(_imageView2.right + kTableCellSmallMargin, 0, width, height);
self.detailTextLabel.frame = CGRectZero;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark TTTableViewCell
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)setObject:(id)object {
if (_item != object) {
[super setObject:object];
TTTableSubtitleItem* item = object;
if (item.text.length) {
self.textLabel.text = item.text;
}
if (item.subtitle.length) {
self.detailTextLabel.text = item.subtitle;
}
if (item.defaultImage) {
self.imageView2.defaultImage = item.defaultImage;
}
if (item.imageURL) {
self.imageView2.urlPath = item.imageURL;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Public
///////////////////////////////////////////////////////////////////////////////////////////////////
- (UILabel*)subtitleLabel {
return self.detailTextLabel;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (TTImageView*)imageView2 {
if (!_imageView2) {
_imageView2 = [[TTImageView alloc] init];
// _imageView2.defaultImage = TTSTYLEVAR(personImageSmall);
// _imageView2.style = TTSTYLE(threadActorIcon);
[self.contentView addSubview:_imageView2];
}
return _imageView2;
}
@end
Jump to Line
Something went wrong with that request. Please try again.