Skip to content
This repository has been archived by the owner on Nov 18, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1 from Label305/feature_landscape
Browse files Browse the repository at this point in the history
Added orientation attribute
  • Loading branch information
tscheepers committed Aug 29, 2014
2 parents 558b098 + 5f4a8d2 commit 347b35a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
5 changes: 3 additions & 2 deletions IVPhoneView.podspec
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
Pod::Spec.new do |s|

s.name = "IVPhoneView"
s.version = "0.1"
s.version = "0.2"
s.summary = "Basic view containing an iPhone graphic, in which you can place a screenshot. Can be used for onboarding experiences."

s.description = <<-DESC
View with a nice iPhone container. Use it to display something within an iPhone graphic. Can be used for onboarding experiences.
Supports different dimensions, colors, and orientations.
DESC

s.homepage = "https://github.com/Label305/IVPhoneView"
s.license = { :type => 'Apache License, Version 2.0', :file => 'LICENSE' }
s.author = { "Thijs Scheepers" => "thijs@label305.com" }

s.source = { :git => "https://github.com/Label305/IVPhoneView.git", :tag => "0.1" }
s.source = { :git => "https://github.com/Label305/IVPhoneView.git", :tag => "0.2" }

s.platform = :ios, '7.0'
s.requires_arc = true
Expand Down
8 changes: 6 additions & 2 deletions IVPhoneView/IVAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
UIViewController *viewController = [UIViewController new];
[self.window setRootViewController:viewController];

IVPhoneView *phoneView = [[IVPhoneView alloc] initWithFrame:CGRectMake(80, 120, 160, 335)];
[viewController.view addSubview:phoneView];
IVPhoneView *portraitPhoneView = [[IVPhoneView alloc] initWithFrame:CGRectMake(80, 210, 160, 335)];
[viewController.view addSubview:portraitPhoneView];

IVPhoneView *landscapePhoneView = [[IVPhoneView alloc] initWithFrame:CGRectMake(-7, 30, 335, 160)];
landscapePhoneView.orientation = IVPhoneViewOrientationLandscape;
[viewController.view addSubview:landscapePhoneView];

[self.window makeKeyAndVisible];
return YES;
Expand Down
10 changes: 10 additions & 0 deletions IVPhoneView/IVPhoneView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@

#import <UIKit/UIKit.h>

typedef NS_ENUM(NSUInteger, IVPhoneViewOrientation) {
IVPhoneViewOrientationPortrait = 0,
IVPhoneViewOrientationLandscape = 1
};

/**
* View with a nice iPhone container. Use it to display something within an iPhone graphic.
*/
@interface IVPhoneView : UIView

/**
* Orientation of the phone view, landscape or portrait
*/
@property (readwrite, nonatomic) IVPhoneViewOrientation orientation;

/**
* Set this property to display a view within the phone
* Setting will also add to subviews
Expand Down
32 changes: 24 additions & 8 deletions IVPhoneView/IVPhoneView.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//

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

#define radians(degrees) (degrees * M_PI/180)


@implementation IVPhoneView
Expand All @@ -16,12 +19,14 @@ - (id)initWithFrame:(CGRect)frame
if (self) {

self.backgroundColor = [UIColor clearColor];
self.buttonColor = [UIColor colorWithRed: 0.643 green: 0.643 blue: 0.643 alpha: 1];
self.phoneColor = [UIColor blackColor];
_buttonColor = [UIColor colorWithRed: 0.643 green: 0.643 blue: 0.643 alpha: 1];
_phoneColor = [UIColor blackColor];

_sideBezzel = 10;
_topBezzel = 45;
_cameraDimentions = 7;

self.sideBezzel = 10;
self.topBezzel = 45;
self.cameraDimentions = 7;
_orientation = IVPhoneViewOrientationPortrait;

}
return self;
Expand Down Expand Up @@ -83,9 +88,20 @@ - (void)layoutSubviews

- (void)drawRect:(CGRect)rect
{
[self drawPhoneWithScreenWidth:rect.size.width - self.sideBezzel * 2.25
screenHeight:rect.size.height - self.sideBezzel * 0.25 - self.topBezzel * 2
sideBezzel:self.sideBezzel topBezzel:self.topBezzel cameraDimention:self.cameraDimentions];
if (self.orientation == IVPhoneViewOrientationLandscape) {
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextRotateCTM( context, radians(90));
CGContextTranslateCTM( context, 0, -rect.size.width );

[self drawPhoneWithScreenWidth:rect.size.height - self.sideBezzel * 2.25
screenHeight:rect.size.width - self.sideBezzel * 0.25 - self.topBezzel * 2
sideBezzel:self.sideBezzel topBezzel:self.topBezzel cameraDimention:self.cameraDimentions];
} else {
[self drawPhoneWithScreenWidth:rect.size.width - self.sideBezzel * 2.25
screenHeight:rect.size.height - self.sideBezzel * 0.25 - self.topBezzel * 2
sideBezzel:self.sideBezzel topBezzel:self.topBezzel cameraDimention:self.cameraDimentions];
}
}

// From PaintCode
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CocoaPods
Add the following lines to your Podfile:

```ruby
pod 'IVPhoneView', '~> 0.1'
pod 'IVPhoneView', '~> 0.2'
```

Usage
Expand All @@ -24,6 +24,12 @@ IVPhoneView *phoneView = [[IVPhoneView alloc] initWithFrame:CGRectMake(80, 120,
phoneView.phoneColor = [UIColor whiteColor]; // For a white iPhone
```
```objective-c
IVPhoneView *landscapePhoneView = [[IVPhoneView alloc] initWithFrame:CGRectMake(-7, 30, 335, 160)];
landscapePhoneView.orientation = IVPhoneViewOrientationLandscape;
[landscapePhoneView setViewInPhone:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myScreenshot"]]];
```

You can set the color and the bezzel of the iPhone graphic. [See the header file.](https://github.com/Label305/IVPhoneView/blob/master/IVPhoneView/IVPhoneView.h)

License
Expand Down

0 comments on commit 347b35a

Please sign in to comment.