Junius Gunaratne a147d7b359 [Catalog] Update AppBar demo design, table view should not have text
Reviewers: ajsecord, featherless, #mdc_ios_owners

Reviewed By: featherless, #mdc_ios_owners

Projects: #material_components_ios

Differential Revision: http://codereview.cc/D640
2016-04-18 14:57:13 -04:00

203 lines
7.9 KiB
Objective-C

/*Copyright 2016-present Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* IMPORTANT:
This file contains supplemental code used to populate the examples with dummy data and/or
instructions. It is not necessary to import this file to implement any Material Design Components.
*/
#import <Foundation/Foundation.h>
#import "HeaderStackViewTypicalUseSupplemental.h"
#import "MaterialNavigationBar.h"
#import "MaterialHeaderStackView.h"
@interface ExampleInstructionsViewHeaderStackViewTypicalUse : UIView
@end
@implementation HeaderStackViewTypicalUse (Supplemental)
- (void)setupExampleViews {
self.exampleView =
[[ExampleInstructionsViewHeaderStackViewTypicalUse alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.exampleView];
self.view.backgroundColor = [UIColor whiteColor];
self.topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[self headerBackgroundImage]];
imageView.frame = self.topView.bounds;
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.topView.clipsToBounds = YES;
[self.topView addSubview:imageView];
self.navBar = [[MDCNavigationBar alloc] initWithFrame:CGRectZero];
self.navBar.tintColor = [UIColor whiteColor];
self.navBar.title = @"Header Stack View";
// Light blue 500
[self.navBar setBackgroundColor:[UIColor colorWithRed:0.012 green:0.663 blue:0.957 alpha:1]];
self.moreButton = [[UIBarButtonItem alloc] initWithTitle:@"More"
style:UIBarButtonItemStylePlain
target:self
action:@selector(didTapToggleButton:)];
self.navBar.rightBarButtonItems = @[ self.moreButton ];
}
- (void)didTapToggleButton:(id)sender {
self.toggled = !self.toggled;
[UIView animateWithDuration:0.4
animations:^{
CGRect frame = self.stackView.frame;
if (self.toggled) {
frame.size.height = 200;
self.moreButton.title = @"Less";
} else {
frame.size = [self.stackView sizeThatFits:self.stackView.bounds.size];
self.moreButton.title = @"More";
}
self.stackView.frame = frame;
[self.stackView layoutIfNeeded];
}];
}
- (UIImage *)headerBackgroundImage {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *imagePath = [bundle pathForResource:@"mdc_theme" ofType:@"png"];
return [UIImage imageWithContentsOfFile:imagePath];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
@end
@implementation HeaderStackViewTypicalUse (CatalogByConvention)
+ (NSArray *)catalogBreadcrumbs {
return @[ @"Header Stack View", @"Header Stack View" ];
}
- (BOOL)catalogShouldHideNavigation {
return YES;
}
+ (NSString *)catalogDescription {
return @"The Header Stack View component is a view that coordinates the layout of two"
" vertically-stacked bar views.";
}
+ (BOOL)catalogIsPrimaryDemo {
return YES;
}
@end
@implementation HeaderStackViewTypicalUse (Rotation)
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
}
@end
@implementation ExampleInstructionsViewHeaderStackViewTypicalUse
- (void)drawRect:(CGRect)rect {
[[UIColor whiteColor] setFill];
[[UIBezierPath bezierPathWithRect:rect] fill];
CGSize textSize = [self textSizeForRect:rect];
CGRect rectForText = CGRectMake(rect.origin.x + rect.size.width / 2.f - textSize.width / 2.f,
rect.origin.y + rect.size.height / 2.f - textSize.height / 2.f,
textSize.width, textSize.height);
[[self instructionsString] drawInRect:rectForText];
[self drawArrowWithFrame:CGRectMake(rect.size.width / 2.f - 12.f,
rect.size.height / 2.f - 58.f - 12.f, 24.f, 24.f)];
}
- (CGSize)textSizeForRect:(CGRect)frame {
return [[self instructionsString]
boundingRectWithSize:frame.size
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
context:nil]
.size;
}
- (NSAttributedString *)instructionsString {
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
[style setAlignment:NSTextAlignmentCenter];
[style setLineBreakMode:NSLineBreakByWordWrapping];
NSDictionary *instructionAttributes1 =
@{NSFontAttributeName : [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline],
NSForegroundColorAttributeName : [UIColor colorWithRed:0.459
green:0.459
blue:0.459
alpha:0.87f],
NSParagraphStyleAttributeName : style};
NSDictionary *instructionAttributes2 =
@{NSFontAttributeName : [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline],
NSForegroundColorAttributeName : [UIColor colorWithRed:0.459
green:0.459
blue:0.459
alpha:0.87f],
NSParagraphStyleAttributeName : style};
NSString *instructionText = @"SWIPE RIGHT\n\n\n\nto go back\n\n\n\n\n\n";
NSMutableAttributedString *instructionsAttributedString = [[NSMutableAttributedString alloc]
initWithString:instructionText];
[instructionsAttributedString setAttributes:instructionAttributes1
range:NSMakeRange(0, 11)];
[instructionsAttributedString setAttributes:instructionAttributes2
range:NSMakeRange(11, instructionText.length - 11)];
return instructionsAttributedString;
}
- (void)drawArrowWithFrame:(CGRect)frame {
UIBezierPath *bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint:CGPointMake(CGRectGetMinX(frame) + 12, CGRectGetMinY(frame) + 4)];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 10.59,
CGRectGetMinY(frame) + 5.41)];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 16.17, CGRectGetMinY(frame) + 11)];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 4, CGRectGetMinY(frame) + 11)];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 4, CGRectGetMinY(frame) + 13)];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 16.17, CGRectGetMinY(frame) + 13)];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 10.59,
CGRectGetMinY(frame) + 18.59)];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 12, CGRectGetMinY(frame) + 20)];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 20, CGRectGetMinY(frame) + 12)];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMinX(frame) + 12, CGRectGetMinY(frame) + 4)];
[bezierPath closePath];
bezierPath.miterLimit = 4;
[[UIColor colorWithRed:0.459
green:0.459
blue:0.459
alpha:0.87f] setFill];
[bezierPath fill];
}
@end