Skip to content

Instantly share code, notes, and snippets.

@jonathontoon
Created February 22, 2014 23:18
Show Gist options
  • Save jonathontoon/9163921 to your computer and use it in GitHub Desktop.
Save jonathontoon/9163921 to your computer and use it in GitHub Desktop.
//
// NotificationCell.m
// HomeworkTableView
//
// Created by Jonathon Toon on 2/21/14.
// Copyright (c) 2014 Jonathon Toon. All rights reserved.
//
#import "NotificationCell.h"
#import "Notification.h"
@interface NotificationCell ()
@property (nonatomic, strong) UIImageView *actorView;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIImageView *metaImage;
@property (nonatomic, strong) UILabel *metaLabel;
@end
@implementation NotificationCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier notificationObject
:(Notification *)notification
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self drawCell];
}
return self;
}
- (void)drawCell
{
// Create cell frame
CGRect cellFrame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, 80);
[self setFrame:cellFrame];
[self.contentView setBackgroundColor:[UIColor whiteColor]];
// Create actor image
CGRect imageFrame = CGRectMake(12, 6, 68, 68);
self.actorView = [[UIImageView alloc] initWithFrame:imageFrame];
[self.actorView setBackgroundColor:[UIColor redColor]];
[self.contentView addSubview:self.actorView];
// Create notification label
CGRect contentFrame = CGRectMake(imageFrame.origin.x+imageFrame.size.width+9, imageFrame.origin.y, 231, 96);
self.contentLabel = [[UILabel alloc] initWithFrame:contentFrame];
[self.contentLabel setFont:[UIFont systemFontOfSize:14]];
[self.contentLabel setText:@"This is an awesome string, dawg. Like, seriously awesome! Wowowow yip cool, awesome"];
[self.contentLabel setLineBreakMode:NSLineBreakByWordWrapping];
[self.contentLabel setNumberOfLines:0];
[self.contentLabel sizeToFit];
[self.contentLabel setTextColor:[UIColor blackColor]];
[self.contentView addSubview:self.contentLabel];
// Create notification type icon
UIImage *notificationType = [UIImage imageNamed:@"name"];
CGRect metaImageFrame = CGRectMake(contentFrame.origin.x, contentFrame.origin.y+contentFrame.size.height-44, 16, 16);
self.metaImage = [[UIImageView alloc] initWithFrame:metaImageFrame];
[self.metaImage setImage:notificationType];
[self.metaImage setBackgroundColor:[UIColor yellowColor]];
[self.contentView addSubview:self.metaImage];
// Create timestamp label
CGRect metaLabelFrame = CGRectMake(metaImageFrame.origin.x+metaImageFrame.size.width+8, contentFrame.origin.y+contentFrame.size.height-44, 200, 16);
self.metaLabel = [[UILabel alloc] initWithFrame:metaLabelFrame];
[self.metaLabel setText:@"4 minutes ago"];
[self.metaLabel setTextColor:[UIColor colorWithRed:0.678 green:0.698 blue:0.733 alpha:1.0]];
[self.metaLabel setFont:[UIFont systemFontOfSize:13]];
[self.metaLabel setBackgroundColor:[UIColor greenColor]];
[self.contentView addSubview:self.metaLabel];
}
-(void)layoutSubviews{
[super layoutSubviews];
}
# pragma mark - Overwrite Methods
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
[super setHighlighted:highlighted animated:NO];
if(highlighted) {
self.contentView.backgroundColor = [UIColor colorWithRed:0.965 green:0.969 blue:0.973 alpha:1.0];
} else {
self.contentView.backgroundColor = [UIColor whiteColor];
}
self.actorView.backgroundColor = [UIColor redColor];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:NO];
if(selected) {
self.contentView.backgroundColor = [UIColor colorWithRed:0.965 green:0.969 blue:0.973 alpha:1.0];
} else {
self.contentView.backgroundColor = [UIColor whiteColor];
}
self.actorView.backgroundColor = [UIColor redColor];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment