summaryrefslogtreecommitdiff
path: root/Juick/MessageCell.m
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2013-10-30 00:50:34 +0400
committerGravatar Vitaly Takmazov2013-10-30 00:50:34 +0400
commit566f122683240ea47f391033ec4e11ef424e7a5c (patch)
treefbe00959f88b3a16d2d4768c1cc223781a377160 /Juick/MessageCell.m
parent7e7b734fc859234c9424b2ed98f5a2afef911de0 (diff)
Working main feed
Diffstat (limited to 'Juick/MessageCell.m')
-rw-r--r--Juick/MessageCell.m134
1 files changed, 134 insertions, 0 deletions
diff --git a/Juick/MessageCell.m b/Juick/MessageCell.m
new file mode 100644
index 0000000..a8b2522
--- /dev/null
+++ b/Juick/MessageCell.m
@@ -0,0 +1,134 @@
+//
+// MessageCell.m
+// Juick
+//
+// Created by Vitaly Takmazov on 29.10.13.
+// Copyright (c) 2013 com.juick. All rights reserved.
+//
+
+#import "MessageCell.h"
+
+@interface MessageCell ()
+
+@property (nonatomic, assign) BOOL didSetupConstraints;
+
+@end
+
+@implementation MessageCell
+
+- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
+{
+ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
+ if (self) {
+ self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
+ [self.titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [self.titleLabel setLineBreakMode:NSLineBreakByTruncatingTail];
+ [self.titleLabel setNumberOfLines:1];
+ [self.titleLabel setTextAlignment:NSTextAlignmentLeft];
+ [self.titleLabel setTextColor:[UIColor blackColor]];
+ [self.titleLabel setBackgroundColor:[UIColor clearColor]];
+
+ self.bodyLabel = [[UILabel alloc] initWithFrame:CGRectZero];
+ [self.bodyLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [self.bodyLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
+ [self.bodyLabel setLineBreakMode:NSLineBreakByTruncatingTail];
+ [self.bodyLabel setNumberOfLines:0];
+ [self.bodyLabel setTextAlignment:NSTextAlignmentLeft];
+ [self.bodyLabel setTextColor:[UIColor darkGrayColor]];
+ [self.bodyLabel setBackgroundColor:[UIColor clearColor]];
+ [self.contentView addSubview:self.titleLabel];
+ [self.contentView addSubview:self.bodyLabel];
+
+ [self updateFonts];
+ }
+ return self;
+}
+
+- (void)setSelected:(BOOL)selected animated:(BOOL)animated
+{
+ [super setSelected:selected animated:animated];
+
+ // Configure the view for the selected state
+}
+
+- (void)updateConstraints {
+ [super updateConstraints];
+
+ 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]];
+
+ [self.contentView addConstraint:[NSLayoutConstraint
+ constraintWithItem:self.bodyLabel
+ attribute:NSLayoutAttributeTop
+ relatedBy:NSLayoutRelationEqual
+ toItem:self.titleLabel
+ attribute:NSLayoutAttributeBottom
+ multiplier:1.0f
+ constant:(kLabelHorizontalInsets / 4)]];
+
+ [self.contentView addConstraint:[NSLayoutConstraint
+ constraintWithItem:self.bodyLabel
+ attribute:NSLayoutAttributeTrailing
+ relatedBy:NSLayoutRelationEqual
+ toItem:self.contentView
+ attribute:NSLayoutAttributeTrailing
+ multiplier:1.0f
+ constant:-kLabelHorizontalInsets]];
+
+ [self.contentView addConstraint:[NSLayoutConstraint
+ constraintWithItem:self.bodyLabel
+ attribute:NSLayoutAttributeBottom
+ relatedBy:NSLayoutRelationEqual
+ toItem:self.contentView
+ attribute:NSLayoutAttributeBottom
+ multiplier:1.0f
+ constant:-(kLabelHorizontalInsets / 2)]];
+
+ self.didSetupConstraints = YES;
+}
+
+
+- (void)updateFonts
+{
+ self.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
+ self.bodyLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
+}
+
+@end