Skip to content
Open

Sid #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ChangingBackground.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
001809EC171C6764002D3E93 /* blue@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 001809E8171C6764002D3E93 /* blue@2x.png */; };
001809ED171C6764002D3E93 /* green.png in Resources */ = {isa = PBXBuildFile; fileRef = 001809E9171C6764002D3E93 /* green.png */; };
001809EE171C6764002D3E93 /* green@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 001809EA171C6764002D3E93 /* green@2x.png */; };
D1A9332D191AD3FB00104BD3 /* BackgroundView.m in Sources */ = {isa = PBXBuildFile; fileRef = D1A9332C191AD3FB00104BD3 /* BackgroundView.m */; };
D1A9332F191AF7E600104BD3 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1A9332E191AF7E600104BD3 /* QuartzCore.framework */; };
D1DD5F3E191C71B300340540 /* CustomButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D1DD5F3D191C71B300340540 /* CustomButton.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -50,13 +53,19 @@
001809E8171C6764002D3E93 /* blue@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "blue@2x.png"; sourceTree = "<group>"; };
001809E9171C6764002D3E93 /* green.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = green.png; sourceTree = "<group>"; };
001809EA171C6764002D3E93 /* green@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "green@2x.png"; sourceTree = "<group>"; };
D1A9332B191AD3FB00104BD3 /* BackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackgroundView.h; sourceTree = "<group>"; };
D1A9332C191AD3FB00104BD3 /* BackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BackgroundView.m; sourceTree = "<group>"; };
D1A9332E191AF7E600104BD3 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
D1DD5F3C191C71B300340540 /* CustomButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomButton.h; sourceTree = "<group>"; };
D1DD5F3D191C71B300340540 /* CustomButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomButton.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
001809B2171C637E002D3E93 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D1A9332F191AF7E600104BD3 /* QuartzCore.framework in Frameworks */,
001809B9171C637E002D3E93 /* UIKit.framework in Frameworks */,
001809BB171C637E002D3E93 /* Foundation.framework in Frameworks */,
001809BD171C637E002D3E93 /* CoreGraphics.framework in Frameworks */,
Expand Down Expand Up @@ -86,6 +95,7 @@
001809B7171C637E002D3E93 /* Frameworks */ = {
isa = PBXGroup;
children = (
D1A9332E191AF7E600104BD3 /* QuartzCore.framework */,
001809B8171C637E002D3E93 /* UIKit.framework */,
001809BA171C637E002D3E93 /* Foundation.framework */,
001809BC171C637E002D3E93 /* CoreGraphics.framework */,
Expand All @@ -96,6 +106,10 @@
001809BE171C637E002D3E93 /* ChangingBackground */ = {
isa = PBXGroup;
children = (
D1A9332B191AD3FB00104BD3 /* BackgroundView.h */,
D1A9332C191AD3FB00104BD3 /* BackgroundView.m */,
D1DD5F3C191C71B300340540 /* CustomButton.h */,
D1DD5F3D191C71B300340540 /* CustomButton.m */,
001809EF171C6768002D3E93 /* BackgroundImages */,
001809D5171C63FC002D3E93 /* AppDelegate */,
001809DC171C6453002D3E93 /* ViewControllers */,
Expand Down Expand Up @@ -238,9 +252,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D1DD5F3E191C71B300340540 /* CustomButton.m in Sources */,
001809C5171C637E002D3E93 /* main.m in Sources */,
001809C9171C637E002D3E93 /* AppDelegate.m in Sources */,
001809D9171C6448002D3E93 /* FirstViewController.m in Sources */,
D1A9332D191AD3FB00104BD3 /* BackgroundView.m in Sources */,
001809E0171C64E4002D3E93 /* SecondViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -356,6 +372,7 @@
001809D4171C637E002D3E93 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
18 changes: 18 additions & 0 deletions ChangingBackground/BackgroundView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// BackgroundImage.h
// ChangingBackground
//
// Created by Siddharth Sukumar on 5/7/14.
// Copyright (c) 2014 Ora Interactive. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface BackgroundView : UIView

@property (nonatomic, strong) UIImage *backgroundImage;

- (void) animatingTheForegroundImageWithImage : (UIImage *) image;


@end
69 changes: 69 additions & 0 deletions ChangingBackground/BackgroundView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// BackgroundImage.m
// ChangingBackground
//
// Created by Siddharth Sukumar on 5/7/14.
// Copyright (c) 2014 Ora Interactive. All rights reserved.
//

#import "BackgroundView.h"
#import <QuartzCore/QuartzCore.h>


@interface BackgroundView ()
@property (strong, nonatomic) UIImageView *imageView;

@end

@implementation BackgroundView


- (id)initWithCoder:(NSCoder *)aDecoder {

self = [super initWithCoder:aDecoder];
if (self){

NSArray *subViews = [self subviews];

id firstObject = subViews[0];

self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 520)];

[self insertSubview:self.imageView belowSubview:firstObject];

}
return self;

}


- (void) animatingTheForegroundImageWithImage : (UIImage *) image {

self.imageView.image = image;

CABasicAnimation *theAnimation;

//within the animation we will adjust the "opacity"value of the layer

theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration=2;

//changing the opacity (1=fully visible, 0=unvisible)

theAnimation.fromValue=[NSNumber numberWithFloat:0.0];
theAnimation.toValue=[NSNumber numberWithFloat:1.0];

[self.imageView.layer addAnimation:theAnimation
forKey:@"animateOpacity"];

}

- (void) drawRect:(CGRect)rect {

[super drawRect:rect];

[self.backgroundImage drawInRect:rect];

}

@end
18 changes: 18 additions & 0 deletions ChangingBackground/CustomButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// CustomButton.h
// ChangingBackground
//
// Created by Siddharth Sukumar on 5/8/14.
// Copyright (c) 2014 Ora Interactive. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CustomButton : UIButton


- (void) indicatingItIsTheFirstViewControler;
- (void) indicatingItIsTheSecondViewController;


@end
92 changes: 92 additions & 0 deletions ChangingBackground/CustomButton.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// CustomButton.m
// ChangingBackground
//
// Created by Siddharth Sukumar on 5/8/14.
// Copyright (c) 2014 Ora Interactive. All rights reserved.
//

#import "CustomButton.h"

@interface CustomButton()

@property BOOL itIsTheFirstViewController;
@property BOOL itIsTheSecondViewController;

@end

@implementation CustomButton

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}

- (void) setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
[self setNeedsDisplay];


}

- (void) indicatingItIsTheFirstViewControler {

self.itIsTheFirstViewController = YES;
self.itIsTheSecondViewController = NO;


}
- (void) indicatingItIsTheSecondViewController {

self.itIsTheSecondViewController = YES;
self.itIsTheFirstViewController = NO;


}




- (void) drawRect:(CGRect)rect {

[super drawRect:rect];
if (self.highlighted){

// Color Declarations
UIColor* color2 = [UIColor colorWithRed: 0 green: 0.629 blue: 1 alpha: 1];

// Rectangle Drawing
UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: rect];
[color2 setFill];
[rectanglePath fill];


// Text Drawing
CGRect textRect = CGRectMake(64, 53, 102, 12);
{
NSString* textContent;

if (self.itIsTheFirstViewController) {
textContent = @"Go Forward";

} else {
textContent = @"Go Back";


}
NSMutableParagraphStyle* textStyle = NSMutableParagraphStyle.defaultParagraphStyle.mutableCopy;
textStyle.alignment = NSTextAlignmentCenter;

NSDictionary* textFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: @"Arial-BoldMT" size: UIFont.systemFontSize], NSForegroundColorAttributeName: UIColor.whiteColor, NSParagraphStyleAttributeName: textStyle};

[textContent drawInRect: CGRectOffset(textRect, 0, (CGRectGetHeight(textRect) - [textContent boundingRectWithSize: textRect.size options: NSStringDrawingUsesLineFragmentOrigin attributes: textFontAttributes context: nil].size.height) / 2) withAttributes: textFontAttributes];

}

}
}
@end
26 changes: 26 additions & 0 deletions ChangingBackground/FirstViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,42 @@

#import "FirstViewController.h"
#import "SecondViewController.h"
#import "BackgroundView.h"
#import "CustomButton.h"

@interface FirstViewController ()
@property (strong, nonatomic) IBOutlet BackgroundView *myView;
@property (strong, nonatomic) IBOutlet CustomButton *goForwardButton;

@end

@implementation FirstViewController

- (void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:YES];

self.myView.backgroundImage = [UIImage imageNamed:@"green"];

[self.goForwardButton indicatingItIsTheFirstViewControler];

// making the corners of the button round

self.goForwardButton.layer.cornerRadius = 10.0;
self.goForwardButton.clipsToBounds = YES;
self.goForwardButton.showsTouchWhenHighlighted = YES;
[self.goForwardButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];

[self.myView animatingTheForegroundImageWithImage:[UIImage imageNamed:@"blue"]];

}


- (IBAction)goForwardButtonPressed {
SecondViewController *secondViewController = SecondViewController.new;
[self.navigationController pushViewController:secondViewController animated:YES];

}

@end

Loading