Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Positioned Post title, date, and content in a scrollview

  • Loading branch information...
commit 789a7bc503d966cf301c975e53ddf715b448eceb 1 parent 0bb05bc
@akinsey akinsey authored
View
2  HI Capacity/PostContentViewController.h
@@ -13,5 +13,7 @@
@property (strong, nonatomic) NSDictionary *post;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
+@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
+@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@end
View
43 HI Capacity/PostContentViewController.m
@@ -17,6 +17,8 @@ @implementation PostContentViewController
@synthesize post;
@synthesize titleLabel;
@synthesize dateLabel;
+@synthesize contentLabel;
+@synthesize scrollView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
@@ -31,16 +33,57 @@ - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
+
+ // Set the title of the view
[self setTitle:[post objectForKey:@"title"]];
+
+ // Set the post title label
[titleLabel setText:[post objectForKey:@"title"]];
+ [titleLabel setNumberOfLines:0];
+ [titleLabel sizeToFit]; // Shrink the frame to fit the text
+
+ // Set spacing and get position of where to place next label
+ int labelSpacing = 10;
+ int newY = titleLabel.frame.size.height + titleLabel.frame.origin.y + labelSpacing;
+
+ // Set the date label
[dateLabel setText:[NSString stringWithFormat:@"(%@)", [post objectForKey:@"date"]]];
+ // Adjust position of the date label
+ CGRect frame = dateLabel.frame;
+ frame.origin.y = newY;
+ dateLabel.frame = frame;
+ [dateLabel setNumberOfLines:0];
+ [dateLabel sizeToFit];
+
+ // Keep track of where to put the post content
+ [contentLabel setText:[post objectForKey:@"content"]];
+ newY = dateLabel.frame.size.height + dateLabel.frame.origin.y + labelSpacing;
+ frame = contentLabel.frame;
+ frame.origin.y = newY;
+ contentLabel.frame = frame;
+ [contentLabel setNumberOfLines:0];
+ [contentLabel sizeToFit];
+
+ // Calculate size of content and set contentSize for scrollview
+ float sizeOfContent = 0;
+ int i;
+ for (i = 0; i < [scrollView.subviews count]; i++) {
+ UIView *view =[scrollView.subviews objectAtIndex:i];
+ sizeOfContent += view.frame.size.height;
+ }
+
+ // Set content size for scroll view
+ scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, sizeOfContent);
+
}
- (void)viewDidUnload
{
[self setTitleLabel:nil];
[self setDateLabel:nil];
+ [self setContentLabel:nil];
+ [self setScrollView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
View
67 HI Capacity/en.lproj/MainStoryboard_iPhone.storyboard
@@ -82,26 +82,41 @@
<rect key="frame" x="0.0" y="64" width="320" height="367"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Label" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" minimumFontSize="10" id="vMO-MZ-4Ig">
- <rect key="frame" x="20" y="20" width="280" height="62"/>
- <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
- <nil key="highlightedColor"/>
- </label>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="10" id="9Cv-6D-JZ7">
- <rect key="frame" x="20" y="90" width="280" height="21"/>
- <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <fontDescription key="fontDescription" type="system" pointSize="15"/>
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
- <nil key="highlightedColor"/>
- </label>
+ <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" id="1iJ-DS-upn">
+ <rect key="frame" x="0.0" y="0.0" width="320" height="367"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <subviews>
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Label" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="14" id="vMO-MZ-4Ig">
+ <rect key="frame" x="20" y="0.0" width="280" height="58"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+ <fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <color key="highlightedColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
+ </label>
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="10" id="9Cv-6D-JZ7">
+ <rect key="frame" x="20" y="66" width="280" height="21"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+ <fontDescription key="fontDescription" type="system" pointSize="15"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <nil key="highlightedColor"/>
+ </label>
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Label" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="10" id="sWw-5y-Xla">
+ <rect key="frame" x="20" y="95" width="280" height="21"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+ <fontDescription key="fontDescription" type="system" pointSize="14"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <nil key="highlightedColor"/>
+ </label>
+ </subviews>
+ </scrollView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" id="fP1-VH-fKk"/>
<connections>
+ <outlet property="contentLabel" destination="sWw-5y-Xla" id="grl-1c-TRh"/>
<outlet property="dateLabel" destination="9Cv-6D-JZ7" id="kbg-dV-Xcq"/>
+ <outlet property="scrollView" destination="1iJ-DS-upn" id="UlW-CT-p6E"/>
<outlet property="titleLabel" destination="vMO-MZ-4Ig" id="QXc-yV-fiS"/>
</connections>
</viewController>
@@ -160,30 +175,6 @@
<point key="canvasLocation" x="701" y="-70"/>
</scene>
</scenes>
- <classes>
- <class className="CalendarViewController" superclassName="TKCalendarMonthTableViewController">
- <source key="sourceIdentifier" type="project" relativePath="./Classes/CalendarViewController.h"/>
- </class>
- <class className="PostContentViewController" superclassName="UIViewController">
- <source key="sourceIdentifier" type="project" relativePath="./Classes/PostContentViewController.h"/>
- <relationships>
- <relationship kind="outlet" name="dateLabel" candidateClass="UILabel"/>
- <relationship kind="outlet" name="titleLabel" candidateClass="UILabel"/>
- </relationships>
- </class>
- <class className="PostsViewController" superclassName="UITableViewController">
- <source key="sourceIdentifier" type="project" relativePath="./Classes/PostsViewController.h"/>
- <relationships>
- <relationship kind="outlet" name="postTableView" candidateClass="UITableView"/>
- </relationships>
- </class>
- <class className="TKCalendarMonthTableViewController" superclassName="TKCalendarMonthViewController">
- <source key="sourceIdentifier" type="project" relativePath="./Classes/TKCalendarMonthTableViewController.h"/>
- </class>
- <class className="TKCalendarMonthViewController" superclassName="UIViewController">
- <source key="sourceIdentifier" type="project" relativePath="./Classes/TKCalendarMonthViewController.h"/>
- </class>
- </classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
Please sign in to comment.
Something went wrong with that request. Please try again.