From 566f122683240ea47f391033ec4e11ef424e7a5c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 30 Oct 2013 00:50:34 +0400 Subject: Working main feed --- Juick/MessageCell.m | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 Juick/MessageCell.m (limited to 'Juick/MessageCell.m') 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 -- cgit v1.2.3