Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Date Formatting for the post date. Also added a autosizing UIWe…

…bView to display the post content. It still isn't behaving as planned, but is displaying the html.
  • Loading branch information...
commit 2fa599d6dead42f61430be94cbcccf633cbe2840 1 parent 789a7bc
@akinsey akinsey authored
View
6 HI Capacity/PostContentViewController.h
@@ -8,12 +8,14 @@
#import <UIKit/UIKit.h>
-@interface PostContentViewController : UIViewController
+@interface PostContentViewController : UIViewController <UIWebViewDelegate>
@property (strong, nonatomic) NSDictionary *post;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
-@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
+@property (strong, nonatomic) IBOutlet UIWebView *contentLabel;
+
+
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@end
View
40 HI Capacity/PostContentViewController.m
@@ -47,7 +47,11 @@ - (void)viewDidLoad
int newY = titleLabel.frame.size.height + titleLabel.frame.origin.y + labelSpacing;
// Set the date label
- [dateLabel setText:[NSString stringWithFormat:@"(%@)", [post objectForKey:@"date"]]];
+ NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
+ [dateFormat setDateFormat:@"EEE, d MMM yyyy HH:mm:ss ZZZ"];
+ NSDate *newDate = [dateFormat dateFromString:[post objectForKey:@"date"]];
+ [dateFormat setDateFormat:@"EEEE, d MMM yyyy h:mm"];
+ [dateLabel setText:[NSString stringWithFormat:@"(%@)", [dateFormat stringFromDate:newDate]]];
// Adjust position of the date label
CGRect frame = dateLabel.frame;
@@ -56,14 +60,25 @@ - (void)viewDidLoad
[dateLabel setNumberOfLines:0];
[dateLabel sizeToFit];
- // Keep track of where to put the post content
- [contentLabel setText:[post objectForKey:@"content"]];
+ // Set settings on the UIWebView
+ [contentLabel setOpaque:FALSE];
+ [contentLabel setBackgroundColor:[UIColor clearColor]];
+
+ // Set the content of the UIWebView and set it's y position
+ [contentLabel loadHTMLString:[post objectForKey:@"content"] baseURL:nil];
newY = dateLabel.frame.size.height + dateLabel.frame.origin.y + labelSpacing;
frame = contentLabel.frame;
- frame.origin.y = newY;
+ frame.origin.y = newY;
contentLabel.frame = frame;
- [contentLabel setNumberOfLines:0];
- [contentLabel sizeToFit];
+
+ //Disable bounce scroll on UIWebView
+ for(UIView *tmpView in ((UIWebView *)contentLabel).subviews){
+ if([tmpView isKindOfClass:[UIScrollView class] ]){
+ ((UIScrollView*)tmpView).scrollEnabled = NO;
+ ((UIScrollView*)tmpView).bounces = NO;
+ break;
+ }
+ }
// Calculate size of content and set contentSize for scrollview
float sizeOfContent = 0;
@@ -75,7 +90,16 @@ - (void)viewDidLoad
// Set content size for scroll view
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, sizeOfContent);
-
+}
+
+- (void)webViewDidFinishLoad:(UIWebView *)webView {
+ //This will resize the content of the webview
+ CGRect frame = webView.frame;
+ frame.size.height = 1;
+ webView.frame = frame;
+ CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
+ frame.size = fittingSize;
+ webView.frame = frame;
}
- (void)viewDidUnload
@@ -84,6 +108,8 @@ - (void)viewDidUnload
[self setDateLabel:nil];
[self setContentLabel:nil];
[self setScrollView:nil];
+ [self setContentLabel:nil];
+ [self setContentLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
View
40 HI Capacity/en.lproj/MainStoryboard_iPhone.storyboard
@@ -87,7 +87,7 @@
<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"/>
+ <rect key="frame" x="20" y="20" width="280" height="58"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
@@ -100,13 +100,11 @@
<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"/>
+ <webView contentMode="scaleToFill" scalesPageToFit="YES" id="HPi-ou-aDx">
+ <rect key="frame" x="20" y="95" width="280" height="272"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <fontDescription key="fontDescription" type="system" pointSize="14"/>
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
- <nil key="highlightedColor"/>
- </label>
+ <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+ </webView>
</subviews>
</scrollView>
</subviews>
@@ -114,7 +112,7 @@
</view>
<navigationItem key="navigationItem" id="fP1-VH-fKk"/>
<connections>
- <outlet property="contentLabel" destination="sWw-5y-Xla" id="grl-1c-TRh"/>
+ <outlet property="contentLabel" destination="HPi-ou-aDx" id="Tpz-vx-Au0"/>
<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"/>
@@ -175,6 +173,32 @@
<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="contentLabel" candidateClass="UIWebView"/>
+ <relationship kind="outlet" name="dateLabel" candidateClass="UILabel"/>
+ <relationship kind="outlet" name="scrollView" candidateClass="UIScrollView"/>
+ <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.