diff options
author | Vitaly Takmazov | 2013-11-03 06:08:35 +0400 |
---|---|---|
committer | Vitaly Takmazov | 2013-11-03 06:08:35 +0400 |
commit | 08574251153406e4755f58c2ee5548ee32e308fb (patch) | |
tree | 26325a6adace092e919234064b0446c3a80812a1 | |
parent | 6dfbafe71aba41bdcf8aba331c1c193c88b42561 (diff) |
avatars
-rw-r--r-- | Juick/Juick-Prefix.pch | 1 | ||||
-rw-r--r-- | Juick/MasterViewController.m | 3 | ||||
-rw-r--r-- | Juick/Message.h | 1 | ||||
-rw-r--r-- | Juick/Message.m | 1 | ||||
-rw-r--r-- | Juick/MessageCell.h | 3 | ||||
-rw-r--r-- | Juick/MessageCell.m | 86 | ||||
-rw-r--r-- | Podfile | 1 | ||||
-rw-r--r-- | Podfile.lock | 3 |
8 files changed, 36 insertions, 63 deletions
diff --git a/Juick/Juick-Prefix.pch b/Juick/Juick-Prefix.pch index 82a2bb4..3db364c 100644 --- a/Juick/Juick-Prefix.pch +++ b/Juick/Juick-Prefix.pch @@ -13,4 +13,5 @@ #ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> + #define MAS_SHORTHAND #endif diff --git a/Juick/MasterViewController.m b/Juick/MasterViewController.m index 26035cd..4ed8df1 100644 --- a/Juick/MasterViewController.m +++ b/Juick/MasterViewController.m @@ -127,6 +127,7 @@ static NSString *CellIdentifier = @"MessageCell"; MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; [cell updateFonts]; Message *msg = [_messages objectAtIndex:indexPath.row]; + [cell.avatar setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://i.juick.com/as/%@.png", msg.userID]]]]]; cell.titleLabel.text = msg.user; cell.bodyLabel.text = msg.text; [cell setNeedsUpdateConstraints]; @@ -136,11 +137,13 @@ static NSString *CellIdentifier = @"MessageCell"; - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; [cell updateFonts]; Message *msg = [_messages objectAtIndex:indexPath.row]; + [cell.avatar setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://i.juick.com/as/%@.png", msg.userID]]]]]; cell.titleLabel.text = msg.user; cell.bodyLabel.text = msg.text; diff --git a/Juick/Message.h b/Juick/Message.h index 071d318..5ec3732 100644 --- a/Juick/Message.h +++ b/Juick/Message.h @@ -14,6 +14,7 @@ @property(nonatomic, copy) NSDecimalNumber *MID; @property(nonatomic, copy) NSDecimalNumber *RID; @property(nonatomic, copy) NSString *user; +@property(nonatomic, copy) NSDecimalNumber *userID; @property(nonatomic, copy) NSString *text; -(id) initWithDictionary:(NSDictionary *)dictionary; diff --git a/Juick/Message.m b/Juick/Message.m index 08f9289..2c35ef4 100644 --- a/Juick/Message.m +++ b/Juick/Message.m @@ -18,6 +18,7 @@ NSString *text = [[dictionary objectForKey:@"body"] stringByDecodingHTMLEntities]; NSDictionary *userDict = [dictionary objectForKey:@"user"]; result.user = [userDict objectForKey:@"uname"]; + result.userID = [userDict objectForKey:@"uid"]; NSArray *tagsArray = [dictionary objectForKey:@"tags"]; if ([tagsArray count] > 0) { result.text = [[NSString alloc] initWithFormat:@"%@\n%@", [tagsArray componentsJoinedByString:@", "], text]; diff --git a/Juick/MessageCell.h b/Juick/MessageCell.h index 299c3b3..f6b7cc3 100644 --- a/Juick/MessageCell.h +++ b/Juick/MessageCell.h @@ -14,7 +14,8 @@ @interface MessageCell : UITableViewCell<TTTAttributedLabelDelegate> -@property (strong, nonatomic) IBOutlet TTTAttributedLabel *titleLabel; +@property (strong, nonatomic) IBOutlet UILabel *titleLabel; +@property (strong, nonatomic) IBOutlet UIImageView *avatar; @property (strong, nonatomic) IBOutlet TTTAttributedLabel *bodyLabel; - (void)updateFonts; 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; } @@ -4,6 +4,7 @@ platform :ios, "6.0" target "Juick" do pod 'MWFeedParser' pod 'TTTAttributedLabel' +pod 'Masonry' end target "JuickTests" do diff --git a/Podfile.lock b/Podfile.lock index 873fcba..b43bda3 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,4 +1,5 @@ PODS: + - Masonry (0.2.4) - MWFeedParser (0.0.1): - MWFeedParser/Feed - MWFeedParser/NSDate+InternetDateTime @@ -11,10 +12,12 @@ PODS: - TTTAttributedLabel (1.7.1) DEPENDENCIES: + - Masonry - MWFeedParser - TTTAttributedLabel SPEC CHECKSUMS: + Masonry: 73df2f346bd1a0044dc9de969aa45aea2f8a9bd8 MWFeedParser: 2ca0852fac352f8333d5f46fdd4b583b921e0c4e TTTAttributedLabel: e504133915a9b11de63cb470ffa2790383a3eb23 |