-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
289 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// CommentCollectionView.h | ||
// unnamed | ||
// | ||
// Created by Casing Chu on 2/23/15. | ||
// Copyright (c) 2015 com.yahoo. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface CommentCollectionView : UIView | ||
- (void)setComments:(NSArray *)comments; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// CommentCollectionView.m | ||
// unnamed | ||
// | ||
// Created by Casing Chu on 2/23/15. | ||
// Copyright (c) 2015 com.yahoo. All rights reserved. | ||
// | ||
|
||
#import "CommentCollectionView.h" | ||
#import "CommentView.h" | ||
|
||
@interface CommentCollectionView () | ||
|
||
@property (nonatomic, strong) NSArray *comments; | ||
@property (nonatomic, strong) NSMutableArray *commentViews; | ||
@property (nonatomic, assign) CGFloat commentHeight; | ||
|
||
@end | ||
|
||
@implementation CommentCollectionView | ||
|
||
/* | ||
// Only override drawRect: if you perform custom drawing. | ||
// An empty implementation adversely affects performance during animation. | ||
- (void)drawRect:(CGRect)rect { | ||
// Drawing code | ||
} | ||
*/ | ||
|
||
- (void)setup { | ||
self.commentViews = [[NSMutableArray alloc] init]; | ||
self.commentHeight = 20.0; | ||
} | ||
|
||
- (id)initWithFrame:(CGRect)frame | ||
{ | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
[self setup]; | ||
} | ||
return self; | ||
} | ||
|
||
- (id)initWithCoder:(NSCoder *)aDecoder { | ||
if ((self = [super initWithCoder:aDecoder])) { | ||
[self setup]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)setComments:(NSArray *)comments { | ||
_comments = comments; | ||
|
||
for (CommentView *view in self.commentViews) { | ||
[view removeFromSuperview]; | ||
} | ||
[self.commentViews removeAllObjects]; | ||
|
||
int count = 1; | ||
for (int i=0;i<comments.count;i++) { | ||
CommentView *view = [[CommentView alloc] init]; | ||
count++; | ||
[self.commentViews addObject:view]; | ||
[self addSubview:view]; | ||
} | ||
|
||
[self setNeedsLayout]; | ||
} | ||
|
||
- (void)layoutSubviews { | ||
[super layoutSubviews]; | ||
|
||
int verticalOffset = 16; | ||
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, | ||
self.commentHeight * self.commentViews.count + | ||
(self.commentViews.count > 0 ? verticalOffset * 2 : 0)); | ||
for (int i=0;i<self.commentViews.count;i++) { | ||
CommentView *view = self.commentViews[i]; | ||
// NSLog(@"Height: %f, Width: %f", view.frame.size.height, view.frame.size.width); | ||
// NSLog(@"Height: %f, Width: %f", self.frame.size.height, self.frame.size.width); | ||
CGFloat y = self.commentHeight * i + verticalOffset; | ||
// NSLog(@"y pos: %f", y); | ||
CGRect imageFrame = CGRectMake(0, y, self.frame.size.width, self.commentHeight); | ||
view.frame = imageFrame; | ||
} | ||
|
||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// CommentView.h | ||
// unnamed | ||
// | ||
// Created by Casing Chu on 2/23/15. | ||
// Copyright (c) 2015 com.yahoo. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface CommentView : UIView | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// CommentView.m | ||
// unnamed | ||
// | ||
// Created by Casing Chu on 2/23/15. | ||
// Copyright (c) 2015 com.yahoo. All rights reserved. | ||
// | ||
|
||
#import "CommentView.h" | ||
|
||
@interface CommentView () | ||
@property (strong, nonatomic) IBOutlet UIView *containerView; | ||
@property (weak, nonatomic) IBOutlet UILabel *nameLabel; | ||
@property (weak, nonatomic) IBOutlet UILabel *commentLabel; | ||
|
||
@end | ||
|
||
@implementation CommentView | ||
|
||
/* | ||
// Only override drawRect: if you perform custom drawing. | ||
// An empty implementation adversely affects performance during animation. | ||
- (void)drawRect:(CGRect)rect { | ||
// Drawing code | ||
} | ||
*/ | ||
|
||
- (void)setup { | ||
UINib *nib = [UINib nibWithNibName:@"CommentView" bundle:nil]; | ||
NSArray *objects = [nib instantiateWithOwner:self options:nil]; | ||
// NSLog(@"Nib Objects Count: %ld", objects.count); | ||
// NSLog(@"Height: %f, Width: %f", self.containerView.frame.size.height, self.containerView.frame.size.width); | ||
|
||
// Setup ContainerView | ||
self.containerView.frame = self.bounds; | ||
[self.containerView setTranslatesAutoresizingMaskIntoConstraints:YES]; | ||
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | ||
[self addSubview:self.containerView]; | ||
[self setNeedsLayout]; | ||
} | ||
|
||
- (id)initWithFrame:(CGRect)frame | ||
{ | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
[self setup]; | ||
} | ||
return self; | ||
} | ||
|
||
- (id)initWithCoder:(NSCoder *)aDecoder { | ||
if ((self = [super initWithCoder:aDecoder])) { | ||
[self setup]; | ||
} | ||
return self; | ||
} | ||
|
||
//- (void)setAnswer:(Answer *)answer { | ||
// _answer = answer; | ||
// self.answerLabel.text = [NSString stringWithFormat:@"%ld. %@", self.index, answer.text]; | ||
// CGFloat percentage = self.total <= 0 ? 0.0 : 1.0f * answer.count / self.total; | ||
// self.percentLabel.text = [NSString stringWithFormat:@"%.1f%%", percentage * 100.0]; | ||
// self.barView.percent = percentage; | ||
// | ||
// [self setNeedsLayout]; | ||
//} | ||
|
||
- (void)layoutSubviews { | ||
[super layoutSubviews]; | ||
|
||
self.containerView.frame = self.bounds; | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CommentView"> | ||
<connections> | ||
<outlet property="commentLabel" destination="rbV-9S-w5h" id="piN-Ka-LB5"/> | ||
<outlet property="containerView" destination="iN0-l3-epB" id="91h-hV-zKQ"/> | ||
<outlet property="nameLabel" destination="2Wv-f4-URV" id="NrW-R7-iQn"/> | ||
</connections> | ||
</placeholder> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<view contentMode="scaleToFill" id="iN0-l3-epB"> | ||
<rect key="frame" x="0.0" y="0.0" width="499" height="20"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Casing Chu" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2Wv-f4-URV"> | ||
<rect key="frame" x="7" y="3" width="66" height="15"/> | ||
<fontDescription key="fontDescription" type="boldSystem" pointSize="12"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="What is up with this question?" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rbV-9S-w5h"> | ||
<rect key="frame" x="81" y="3" width="168" height="15"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="12"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | ||
<constraints> | ||
<constraint firstAttribute="centerY" secondItem="2Wv-f4-URV" secondAttribute="centerY" id="APH-J2-chS"/> | ||
<constraint firstItem="2Wv-f4-URV" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="8" id="Vh9-hV-VgE"/> | ||
<constraint firstAttribute="centerY" secondItem="rbV-9S-w5h" secondAttribute="centerY" id="mju-4i-VYO"/> | ||
<constraint firstItem="rbV-9S-w5h" firstAttribute="leading" secondItem="2Wv-f4-URV" secondAttribute="trailing" constant="8" id="mvF-xE-wrp"/> | ||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="rbV-9S-w5h" secondAttribute="trailing" constant="8" id="qeT-Se-FsS"/> | ||
</constraints> | ||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/> | ||
<point key="canvasLocation" x="403.5" y="157"/> | ||
</view> | ||
</objects> | ||
<simulatedMetricsContainer key="defaultSimulatedMetrics"> | ||
<simulatedStatusBarMetrics key="statusBar"/> | ||
<simulatedOrientationMetrics key="orientation"/> | ||
<simulatedScreenMetrics key="destination" type="retina4"/> | ||
</simulatedMetricsContainer> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.