summaryrefslogtreecommitdiff
path: root/Juick/MessageCell.m
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/MessageCell.m')
-rw-r--r--Juick/MessageCell.m86
1 files changed, 24 insertions, 62 deletions
diff --git a/Juick/MessageCell.m b/Juick/MessageCell.m
index dc698b3..f20acbe 100644
--- a/Juick/MessageCell.m
+++ b/Juick/MessageCell.m
@@ -7,6 +7,7 @@
//
#import "MessageCell.h"
+#import "Masonry.h"
@interface MessageCell ()
@@ -20,7 +21,10 @@
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
- self.titleLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
+ 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];
@@ -38,6 +42,7 @@
[self.bodyLabel setTextAlignment:NSTextAlignmentLeft];
[self.bodyLabel setTextColor:[UIColor darkGrayColor]];
[self.bodyLabel setBackgroundColor:[UIColor clearColor]];
+ [self.contentView addSubview:self.avatar];
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.bodyLabel];
@@ -58,70 +63,27 @@
if (self.didSetupConstraints) return;
- [self.contentView addConstraint:[NSLayoutConstraint
- constraintWithItem:self.titleLabel
- attribute:NSLayoutAttributeLeading
- relatedBy:NSLayoutRelationEqual
- toItem:self.contentView
- attribute:NSLayoutAttributeLeading
- multiplier:1.0f
- constant:kLabelHorizontalInsets]];
-
- [self.contentView addConstraint:[NSLayoutConstraint
- constraintWithItem:self.titleLabel
- attribute:NSLayoutAttributeTop
- relatedBy:NSLayoutRelationEqual
- toItem:self.contentView
- attribute:NSLayoutAttributeTop
- multiplier:1.0f
- constant:(kLabelHorizontalInsets / 2)]];
-
- [self.contentView addConstraint:[NSLayoutConstraint
- constraintWithItem:self.titleLabel
- attribute:NSLayoutAttributeTrailing
- relatedBy:NSLayoutRelationEqual
- toItem:self.contentView
- attribute:NSLayoutAttributeTrailing
- multiplier:1.0f
- constant:-kLabelHorizontalInsets]];
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- [self.contentView addConstraint:[NSLayoutConstraint
- constraintWithItem:self.bodyLabel
- attribute:NSLayoutAttributeLeading
- relatedBy:NSLayoutRelationEqual
- toItem:self.contentView
- attribute:NSLayoutAttributeLeading
- multiplier:1.0f
- constant:kLabelHorizontalInsets]];
+ UIEdgeInsets padding = UIEdgeInsetsMake(10, 20, 10, 20);
- [self.contentView addConstraint:[NSLayoutConstraint
- constraintWithItem:self.bodyLabel
- attribute:NSLayoutAttributeTop
- relatedBy:NSLayoutRelationEqual
- toItem:self.titleLabel
- attribute:NSLayoutAttributeBottom
- multiplier:1.0f
- constant:(kLabelHorizontalInsets / 4)]];
+ [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.width.lessThanOrEqualTo(@32);
+ make.height.lessThanOrEqualTo(@32);
+ }];
- [self.contentView addConstraint:[NSLayoutConstraint
- constraintWithItem:self.bodyLabel
- attribute:NSLayoutAttributeTrailing
- relatedBy:NSLayoutRelationEqual
- toItem:self.contentView
- attribute:NSLayoutAttributeTrailing
- multiplier:1.0f
- constant:-kLabelHorizontalInsets]];
+ [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
+ make.leading.equalTo(self.avatar.trailing).with.offset(padding.right);
+ make.top.equalTo(self.contentView.top).with.offset(padding.top);
+ make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right);
+ }];
- [self.contentView addConstraint:[NSLayoutConstraint
- constraintWithItem:self.bodyLabel
- attribute:NSLayoutAttributeBottom
- relatedBy:NSLayoutRelationEqual
- toItem:self.contentView
- attribute:NSLayoutAttributeBottom
- multiplier:1.0f
- constant:-(kLabelHorizontalInsets / 2)]];
+ [self.bodyLabel makeConstraints:^(MASConstraintMaker *make) {
+ make.leading.equalTo(self.contentView.leading).with.offset(padding.left);
+ make.top.equalTo(self.avatar.bottom).with.offset(padding.top);
+ make.trailing.equalTo(self.contentView.trailing).with.offset(-padding.right);
+ make.bottom.equalTo(self.contentView.bottom).with.offset(-padding.bottom);
+ }];
self.didSetupConstraints = YES;
}