adding in classes for font size and style

This commit is contained in:
Roy Yang 2012-06-26 23:12:54 -07:00
parent 80ac10856f
commit efe2572cd7
9 changed files with 127 additions and 85 deletions

View file

@ -19,7 +19,7 @@
@property (nonatomic, retain) IBOutlet NewsBlurAppDelegate *appDelegate;
@property (retain, nonatomic) IBOutlet UISegmentedControl *fontStyleSegment;
@property (retain, nonatomic) IBOutlet UISegmentedControl *fontSizeSgement;
@property (retain, nonatomic) IBOutlet UISegmentedControl *fontSizeSegment;
- (IBAction)changeFontStyle:(id)sender;
- (IBAction)changeFontSize:(id)sender;

View file

@ -14,7 +14,7 @@
@synthesize appDelegate;
@synthesize fontStyleSegment;
@synthesize fontSizeSgement;
@synthesize fontSizeSegment;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
@ -33,33 +33,27 @@
- (void)viewWillAppear:(BOOL)animated {
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
if ([userPreferences stringForKey:@"fontStyle"]) {
if ([[userPreferences stringForKey:@"fontStyle"] isEqualToString:@"NB-san-serif"]) {
[self setSanSerif];
[fontStyleSegment setSelectedSegmentIndex:0];
} else if ([[userPreferences stringForKey:@"fontStyle"] isEqualToString:@"NB-serif"]) {
[self setSerif];
[fontStyleSegment setSelectedSegmentIndex:1];
}
}
int userPreferenceFontSize = [userPreferences integerForKey:@"fontSize"];
if(userPreferenceFontSize){
switch (userPreferenceFontSize) {
case 12:
[fontSizeSgement setSelectedSegmentIndex:0];
break;
case 14:
[fontSizeSgement setSelectedSegmentIndex:1];
break;
case 16:
[fontSizeSgement setSelectedSegmentIndex:2];
break;
case 22:
[fontSizeSgement setSelectedSegmentIndex:3];
break;
case 26:
[fontSizeSgement setSelectedSegmentIndex:4];
break;
default:
break;
if([userPreferences stringForKey:@"fontSizing"]){
NSString *fontSize = [NSString stringWithFormat:@"%@", [userPreferences stringForKey:@"fontSizing"]];
if ([fontSize isEqualToString:@"NB-extra-small"]) {
[fontSizeSegment setSelectedSegmentIndex:0];
} else if ([fontSize isEqualToString:@"NB-small"]) {
[fontSizeSegment setSelectedSegmentIndex:1];
} else if ([fontSize isEqualToString:@"NB-medium"]) {
[fontSizeSegment setSelectedSegmentIndex:2];
} else if ([fontSize isEqualToString:@"NB-large"]) {
[fontSizeSegment setSelectedSegmentIndex:3];
} else if ([fontSize isEqualToString:@"NB-extra-large"]) {
[fontSizeSegment setSelectedSegmentIndex:4];
}
}
// Do any additional setup after loading the view from its nib.
@ -67,8 +61,7 @@
- (void)viewDidUnload
{
[self setFontStyleSegment:nil];
[self setFontSizeSgement:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
@ -82,7 +75,7 @@
- (void)dealloc {
[appDelegate release];
[fontStyleSegment release];
[fontSizeSgement release];
[fontSizeSegment release];
[super dealloc];
}
@ -98,20 +91,20 @@
- (IBAction)changeFontSize:(id)sender {
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
if ([sender selectedSegmentIndex] == 0) {
[appDelegate.storyDetailViewController setFontSize:12];
[userPreferences setInteger:12 forKey:@"fontSize"];
[appDelegate.storyDetailViewController changeFontSize:@"NB-extra-small"];
[userPreferences setObject:@"NB-extra-small" forKey:@"fontSizing"];
} else if ([sender selectedSegmentIndex] == 1) {
[appDelegate.storyDetailViewController setFontSize:14];
[userPreferences setInteger:14 forKey:@"fontSize"];
[appDelegate.storyDetailViewController changeFontSize:@"NB-small"];
[userPreferences setObject:@"NB-small" forKey:@"fontSizing"];
} else if ([sender selectedSegmentIndex] == 2) {
[appDelegate.storyDetailViewController setFontSize:16];
[userPreferences setInteger:16 forKey:@"fontSize"];
[appDelegate.storyDetailViewController changeFontSize:@"NB-medium"];
[userPreferences setObject:@"NB-medium" forKey:@"fontSizing"];
} else if ([sender selectedSegmentIndex] == 3) {
[appDelegate.storyDetailViewController setFontSize:22];
[userPreferences setInteger:22 forKey:@"fontSize"];
[appDelegate.storyDetailViewController changeFontSize:@"NB-large"];
[userPreferences setObject:@"NB-large" forKey:@"fontSizing"];
} else if ([sender selectedSegmentIndex] == 4) {
[appDelegate.storyDetailViewController setFontSize:26];
[userPreferences setInteger:26 forKey:@"fontSize"];
[appDelegate.storyDetailViewController changeFontSize:@"NB-extra-large"];
[userPreferences setObject:@"NB-extra-large" forKey:@"fontSizing"];
}
[userPreferences synchronize];
}

View file

@ -158,11 +158,11 @@
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">fontSizeSgement</string>
<string key="label">fontSizeSegment</string>
<reference key="source" ref="841351856"/>
<reference key="destination" ref="583946447"/>
</object>
<int key="connectionID">33</int>
<int key="connectionID">34</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
@ -237,7 +237,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">33</int>
<int key="maxID">34</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -601,7 +601,7 @@
</dictionary>
<dictionary class="NSMutableDictionary" key="outlets">
<string key="appDelegate">NewsBlurAppDelegate</string>
<string key="fontSizeSgement">UISegmentedControl</string>
<string key="fontSizeSegment">UISegmentedControl</string>
<string key="fontStyleSegment">UISegmentedControl</string>
<string key="largeFontSizeLabel">UILabel</string>
<string key="smallFontSizeLabel">UILabel</string>
@ -611,8 +611,8 @@
<string key="name">appDelegate</string>
<string key="candidateClassName">NewsBlurAppDelegate</string>
</object>
<object class="IBToOneOutletInfo" key="fontSizeSgement">
<string key="name">fontSizeSgement</string>
<object class="IBToOneOutletInfo" key="fontSizeSegment">
<string key="name">fontSizeSegment</string>
<string key="candidateClassName">UISegmentedControl</string>
</object>
<object class="IBToOneOutletInfo" key="fontStyleSegment">
@ -992,6 +992,7 @@
<string key="doSwitchSitesUnread">id</string>
<string key="sectionTapped:">UIButton</string>
<string key="sectionUntapped:">UIButton</string>
<string key="sectionUntappedOutside:">UIButton</string>
<string key="selectIntelligence">id</string>
<string key="showMenuButton">id</string>
</dictionary>
@ -1008,6 +1009,10 @@
<string key="name">sectionUntapped:</string>
<string key="candidateClassName">UIButton</string>
</object>
<object class="IBActionInfo" key="sectionUntappedOutside:">
<string key="name">sectionUntappedOutside:</string>
<string key="candidateClassName">UIButton</string>
</object>
<object class="IBActionInfo" key="selectIntelligence">
<string key="name">selectIntelligence</string>
<string key="candidateClassName">id</string>
@ -1152,6 +1157,7 @@
<string key="superclassName">UIViewController</string>
<dictionary class="NSMutableDictionary" key="actions">
<string key="doCancelButton:">id</string>
<string key="doReplyToComment:">id</string>
<string key="doShareThisStory:">id</string>
<string key="doToggleButton:">id</string>
</dictionary>
@ -1160,6 +1166,10 @@
<string key="name">doCancelButton:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="doReplyToComment:">
<string key="name">doReplyToComment:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="doShareThisStory:">
<string key="name">doShareThisStory:</string>
<string key="candidateClassName">id</string>
@ -1173,9 +1183,10 @@
<string key="appDelegate">NewsBlurAppDelegate</string>
<string key="commentField">UITextView</string>
<string key="facebookButton">UIButton</string>
<string key="fontSizeSegment">UISegmentedControl</string>
<string key="siteFavicon">UIImageView</string>
<string key="siteInformation">UILabel</string>
<string key="submitButton">UIBarButtonItem</string>
<string key="toolbarTitle">UIBarButtonItem</string>
<string key="twitterButton">UIButton</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
@ -1191,10 +1202,6 @@
<string key="name">facebookButton</string>
<string key="candidateClassName">UIButton</string>
</object>
<object class="IBToOneOutletInfo" key="fontSizeSegment">
<string key="name">fontSizeSegment</string>
<string key="candidateClassName">UISegmentedControl</string>
</object>
<object class="IBToOneOutletInfo" key="siteFavicon">
<string key="name">siteFavicon</string>
<string key="candidateClassName">UIImageView</string>
@ -1203,6 +1210,14 @@
<string key="name">siteInformation</string>
<string key="candidateClassName">UILabel</string>
</object>
<object class="IBToOneOutletInfo" key="submitButton">
<string key="name">submitButton</string>
<string key="candidateClassName">UIBarButtonItem</string>
</object>
<object class="IBToOneOutletInfo" key="toolbarTitle">
<string key="name">toolbarTitle</string>
<string key="candidateClassName">UIBarButtonItem</string>
</object>
<object class="IBToOneOutletInfo" key="twitterButton">
<string key="name">twitterButton</string>
<string key="candidateClassName">UIButton</string>
@ -1238,7 +1253,6 @@
<dictionary class="NSMutableDictionary" key="actions">
<string key="doNextUnreadStory">id</string>
<string key="doPreviousStory">id</string>
<string key="doShareButton:">id</string>
<string key="toggleFontSize:">id</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="actionInfosByName">
@ -1250,10 +1264,6 @@
<string key="name">doPreviousStory</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="doShareButton:">
<string key="name">doShareButton:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="toggleFontSize:">
<string key="name">toggleFontSize:</string>
<string key="candidateClassName">id</string>

View file

@ -97,7 +97,6 @@
self.window.rootViewController = self.splitStoryController;
} else {
navigationController.viewControllers = [NSArray arrayWithObject:feedsViewController];
[window addSubview:navigationController.view];
@ -441,6 +440,7 @@
}
- (void)adjustStoryDetailWebView:(BOOL)init shouldCheckLayout:(BOOL)checkLayout {
return;
UINavigationController *navController = self.navigationController;
if (UIInterfaceOrientationIsPortrait(splitStoryDetailViewController.interfaceOrientation)) {

View file

@ -51,13 +51,13 @@
}
- (void)viewDidLoad {
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Home"
style:UIBarButtonItemStylePlain
target:self
action:@selector(showMenuButton)]
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(showMenuButton)]
autorelease];
[self.navigationItem.leftBarButtonItem setImage:[UIImage imageNamed:@"53-house.png"]];
[self.navigationItem.rightBarButtonItem setImage:[UIImage imageNamed:@"add_button.png"]];
[appDelegate showNavigationBar:NO];
self.viewShowingAllFeeds = NO;
pull = [[PullToRefreshView alloc] initWithScrollView:self.feedTitlesTable];
@ -340,7 +340,7 @@
}
[popoverController setPopoverContentSize:CGSizeMake(200, 130)];
[popoverController presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem
[popoverController presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[appDelegate showFeedsMenu];

View file

@ -49,7 +49,7 @@
- (void)setActiveStory;
- (IBAction)toggleFontSize:(id)sender;
- (void)setFontStyle:(NSString *)fontStyle;
- (void)setFontSize:(float)fontSize;
- (void)changeFontSize:(NSString *)fontSize;
- (NSString *)getComments;
- (NSString *)getComment:(NSDictionary *)commentDict;
- (NSString *)getReplies:(NSArray *)replies;

View file

@ -263,15 +263,27 @@
- (void)showStory {
NSString *commentsString = [self getComments];
NSString *headerString, *sharingHtmlString;
NSString *customBodyClass = @"";
NSString *fontStyleClass = @"";
NSString *fontSizeClass = @"";
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
if ([userPreferences stringForKey:@"fontStyle"]){
customBodyClass = [customBodyClass stringByAppendingString:[userPreferences stringForKey:@"fontStyle"]];
fontStyleClass = [fontStyleClass stringByAppendingString:[userPreferences stringForKey:@"fontStyle"]];
} else {
customBodyClass = [customBodyClass stringByAppendingString:@"NB-san-serif"];
fontStyleClass = [fontStyleClass stringByAppendingString:@"NB-san-serif"];
}
NSLog(@"fontClass is %@", fontStyleClass);
if ([userPreferences stringForKey:@"fontSizing"]){
fontSizeClass = [fontSizeClass stringByAppendingString:[userPreferences stringForKey:@"fontSizing"]];
} else {
fontSizeClass = [fontSizeClass stringByAppendingString:@"NB-medium"];
}
NSLog(@"fontSizing is %@", fontSizeClass);
// set up layout values based on iPad/iPhone
headerString = [NSString stringWithFormat:@
"<script src=\"zepto.js\"></script>"
@ -321,13 +333,19 @@
story_tags];
NSString *htmlString = [NSString stringWithFormat:@
"<html><head>%@</head>"
"<body id=\"story_pane\" class=\"%@\">%@"
"<body id=\"story_pane\">"
"<div class=\"%@\" id=\"NB-font-size\">"
"<div class=\"%@\" id=\"NB-font-style\">"
"%@"
"<div class=\"NB-story\">%@ </div>"
"<div id=\"NB-comments-wrapper\">%@</div>" // comments
"%@" // share
"</div>" // font-style
"</div>" // font-size
"</body></html>",
headerString,
customBodyClass,
headerString,
fontSizeClass,
fontStyleClass,
storyHeader,
[appDelegate.activeStory objectForKey:@"story_content"],
commentsString,
@ -422,16 +440,16 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
if ([userPreferences integerForKey:@"fontSize"]){
[self setFontSize:[userPreferences integerForKey:@"fontSize"]];
if ([userPreferences integerForKey:@"fontSizing"]){
[self changeFontSize:[userPreferences stringForKey:@"fontSizing"]];
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
if ([userPreferences integerForKey:@"fontSize"]){
[self setFontSize:[userPreferences integerForKey:@"fontSize"]];
if ([userPreferences integerForKey:@"fontSizing"]){
[self changeFontSize:[userPreferences stringForKey:@"fontSizing"]];
}
}
@ -596,8 +614,9 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
}
- (void)setFontSize:(float)fontSize {
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.fontSize= '%fpx'",
- (void)changeFontSize:(NSString *)fontSize {
NSLog(@"fontSize is %@", fontSize);
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementById('NB-font-size').setAttribute('class', '%@')",
fontSize];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
[jsString release];
@ -612,7 +631,7 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
}
[userPreferences synchronize];
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.fontFamily= '%@'",
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementById('NB-font-style').setAttribute('class', '%@')",
fontStyle];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
[jsString release];

View file

@ -49,9 +49,10 @@
<object class="IBUILabel" id="750430533">
<reference key="NSNextResponder" ref="994014136"/>
<int key="NSvFlags">265</int>
<string key="NSFrame">{{613, 40}, {128, 15}}</string>
<string key="NSFrame">{{620, 40}, {128, 15}}</string>
<reference key="NSSuperview" ref="994014136"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<object class="NSColor" key="IBUIBackgroundColor" id="932003208">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
@ -90,7 +91,7 @@
<object class="IBUILabel" id="417683225">
<reference key="NSNextResponder" ref="994014136"/>
<int key="NSvFlags">290</int>
<string key="NSFrame">{{33, 5}, {708, 34}}</string>
<string key="NSFrame">{{33, 8}, {728, 34}}</string>
<reference key="NSSuperview" ref="994014136"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="194816084"/>
@ -170,7 +171,7 @@
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
</object>
</object>
<string key="NSFrameSize">{748, 59}</string>
<string key="NSFrameSize">{768, 59}</string>
<reference key="NSSuperview" ref="749780469"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="523799572"/>
@ -191,7 +192,6 @@
<reference key="NSNextKeyView" ref="994014136"/>
<reference key="IBUIBackgroundColor" ref="932003208"/>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<int key="IBUIAccessoryType">1</int>
<float key="IBUIIndentationWidth">0.0</float>
<reference key="IBUIContentView" ref="994014136"/>
<string key="IBUIReuseIdentifier">FeedDetailCellIdentifier</string>
@ -209,7 +209,7 @@
<object class="IBUIView" id="111782255">
<reference key="NSNextResponder" ref="247257992"/>
<int key="NSvFlags">290</int>
<string key="NSFrame">{{0, -1}, {768, 20}}</string>
<string key="NSFrame">{{0, -1}, {788, 20}}</string>
<reference key="NSSuperview" ref="247257992"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="1001310564"/>
@ -219,9 +219,10 @@
<object class="IBUILabel" id="607536273">
<reference key="NSNextResponder" ref="247257992"/>
<int key="NSvFlags">265</int>
<string key="NSFrame">{{607, 61}, {141, 15}}</string>
<string key="NSFrame">{{607, 60}, {141, 15}}</string>
<reference key="NSSuperview" ref="247257992"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<reference key="IBUIBackgroundColor" ref="932003208"/>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUIContentMode">7</int>
@ -248,7 +249,7 @@
<object class="IBUILabel" id="753396836">
<reference key="NSNextResponder" ref="247257992"/>
<int key="NSvFlags">290</int>
<string key="NSFrame">{{34, 25}, {708, 34}}</string>
<string key="NSFrame">{{34, 28}, {728, 34}}</string>
<reference key="NSSuperview" ref="247257992"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="450494992"/>
@ -277,7 +278,7 @@
<object class="IBUILabel" id="450494992">
<reference key="NSNextResponder" ref="247257992"/>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{34, 61}, {122, 15}}</string>
<string key="NSFrame">{{34, 60}, {122, 15}}</string>
<reference key="NSSuperview" ref="247257992"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="607536273"/>
@ -313,7 +314,7 @@
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
</object>
</object>
<string key="NSFrameSize">{748, 79}</string>
<string key="NSFrameSize">{768, 79}</string>
<reference key="NSSuperview" ref="183700415"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="111782255"/>
@ -332,7 +333,6 @@
<reference key="IBUIBackgroundColor" ref="932003208"/>
<int key="IBUITag">1</int>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<int key="IBUIAccessoryType">1</int>
<float key="IBUIIndentationWidth">0.0</float>
<reference key="IBUIContentView" ref="247257992"/>
<string key="IBUIReuseIdentifier">RiverFeedDetailCellIdentifier</string>

View file

@ -36,11 +36,31 @@ body {
/* FONT RENDERING */
body {
.NB-extra-small {
line-height: 1.6em;
font-size: 12px;
}
.NB-small {
line-height: 1.6em;
font-size: 14px;
}
.NB-medium {
line-height: 1.6em;
font-size: 16px;
}
.NB-large {
line-height: 1.6em;
font-size: 22px;
}
.NB-extra-large {
line-height: 1.6em;
font-size: 26px;
}
.NB-san-serif {
font-family: Helvetica;
}