diff options
Diffstat (limited to 'Juick/MessageCell.m')
-rw-r--r-- | Juick/MessageCell.m | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/Juick/MessageCell.m b/Juick/MessageCell.m index 0777dfd..3f06436 100644 --- a/Juick/MessageCell.m +++ b/Juick/MessageCell.m @@ -9,6 +9,7 @@ #import "MessageCell.h" #import "ColorsAndButtons.h" #import "Masonry.h" +#import "JMImageCache.h" @interface MessageCell () @@ -23,12 +24,10 @@ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self setBackgroundColor:[UIColor whiteColor]]; - self.avatar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; [self.avatar setBackgroundColor:[UIColor clearColor]]; self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - [self.titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.titleLabel setLineBreakMode:NSLineBreakByTruncatingTail]; [self.titleLabel setNumberOfLines:1]; [self.titleLabel setTextAlignment:NSTextAlignmentLeft]; @@ -36,7 +35,6 @@ [self.titleLabel setBackgroundColor:[UIColor clearColor]]; self.timestampLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - [self.timestampLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.timestampLabel setLineBreakMode:NSLineBreakByTruncatingTail]; [self.timestampLabel setNumberOfLines:1]; [self.timestampLabel setTextAlignment:NSTextAlignmentLeft]; @@ -46,7 +44,6 @@ self.bodyLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero]; self.bodyLabel.dataDetectorTypes = NSTextCheckingTypeLink; self.bodyLabel.delegate = self; - [self.bodyLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.bodyLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; [self.bodyLabel setLineBreakMode:NSLineBreakByTruncatingTail]; [self.bodyLabel setNumberOfLines:0]; @@ -94,41 +91,42 @@ [self.avatar makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView.top).with.offset(padding.top); - make.leading.equalTo(self.contentView.leading).with.offset(padding.left); + make.left.equalTo(self.contentView.left).with.offset(padding.left); make.width.equalTo(@32); make.height.equalTo(@32); }]; [self.titleLabel makeConstraints:^(MASConstraintMaker *make) { - make.leading.equalTo(self.avatar.trailing).with.offset(padding.right); + make.left.equalTo(self.avatar.right).with.offset(padding.right); make.top.equalTo(self.contentView.top).with.offset(padding.top); - make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.right.equalTo(self.contentView.right).with.offset(-padding.right); }]; [self.timestampLabel makeConstraints:^(MASConstraintMaker *make) { - make.leading.equalTo(self.avatar.trailing).with.offset(padding.left); + make.left.equalTo(self.avatar.right).with.offset(padding.left); make.top.equalTo(self.titleLabel.bottom).with.offset(padding.top /2); - make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.right.equalTo(self.contentView.right).with.offset(-padding.right); + make.bottom.equalTo(self.bodyLabel.top).with.offset(-padding.bottom); }]; - [self.bodyLabel makeConstraints:^(MASConstraintMaker *make) { - make.leading.equalTo(self.contentView.leading).with.offset(padding.left); + make.left.equalTo(self.contentView.left).with.offset(padding.left); make.top.equalTo(self.timestampLabel.bottom).with.offset(padding.top); - make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.right.equalTo(self.contentView.right).with.offset(-padding.right); make.bottom.equalTo(self.attach.top).with.offset(-padding.bottom); }]; [self.attach makeConstraints:^(MASConstraintMaker *make) { - make.leading.equalTo(self.contentView.leading).with.offset(padding.left); + make.left.equalTo(self.contentView.left).with.offset(padding.left); make.bottom.equalTo(self.summaryLabel.top).with.offset(-padding.bottom); - make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.right.equalTo(self.contentView.right).with.offset(-padding.right); make.top.equalTo(self.bodyLabel.bottom).with.offset(padding.top); }]; [self.summaryLabel makeConstraints:^(MASConstraintMaker *make) { - make.leading.equalTo(self.contentView.leading).with.offset(padding.left); + make.left.equalTo(self.contentView.left).with.offset(padding.left); make.bottom.equalTo(self.contentView.bottom).with.offset(-padding.bottom); - make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right); + make.right.equalTo(self.contentView.right).with.offset(-padding.right); + make.top.equalTo(self.attach.bottom).with.offset(padding.top); }]; @@ -148,7 +146,7 @@ } - (void) bind:(Message *)msg { - [self.avatar setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://i.juick.com/as/%@.png", msg.userID]]]; + [self.avatar setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://i.juick.com/as/%d.png", [msg.userID intValue]]]]; self.titleLabel.text = msg.user; self.timestampLabel.text = msg.timestamp; @@ -167,7 +165,7 @@ [msg.text stringByDecodingHTMLEntities]]; } if ([msg.attach length] > 0) { - [self.attach setImageWithURL:[NSURL URLWithString:msg.attach]]; + [self.attach setImageWithURL:[NSURL URLWithString:msg.attach] key:[NSString stringWithFormat:@"%d", [msg.MID intValue]] placeholder:[UIImage imageNamed:@"AttachPlaceholder.png"]]; } else { self.attach.image = nil; } |