Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
bec6cbeb
Commit
bec6cbeb
authored
Feb 01, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated example project to include async image loading with updated internals using NSURLSession.
parent
eff18099
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
12 deletions
+38
-12
Examples/Programmatic/MaterialLayer/MaterialLayer/Info.plist
+15
-0
Examples/Programmatic/MaterialLayer/MaterialLayer/ViewController.swift
+8
-1
Sources/Material+UIImage+Network.swift
+13
-10
Sources/Material+UIImage.swift
+2
-1
No files found.
Examples/Programmatic/MaterialLayer/MaterialLayer/Info.plist
View file @
bec6cbeb
...
@@ -42,5 +42,20 @@
...
@@ -42,5 +42,20 @@
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
/
a
rr
a
y
>
<
/
a
rr
a
y
>
<
k
e
y
>
NSAppTransportSecurity
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
NSExceptionDomains
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
cosmicmind.io
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
NSIncludesSubdomains
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
NSTemporaryExceptionAllowsInsecureHTTPLoads
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
NSTemporaryExceptionMinimumTLSVersion
<
/k
e
y
>
<
string
>
TLSv1.1
<
/string
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
/plist
>
<
/plist
>
Examples/Programmatic/MaterialLayer/MaterialLayer/ViewController.swift
View file @
bec6cbeb
...
@@ -60,10 +60,17 @@ class ViewController: UIViewController {
...
@@ -60,10 +60,17 @@ class ViewController: UIViewController {
*/
*/
private
func
prepareGeneralMaterialLayerExample
()
{
private
func
prepareGeneralMaterialLayerExample
()
{
let
materialLayer
:
MaterialLayer
=
MaterialLayer
(
frame
:
CGRectMake
(
132
,
132
,
150
,
150
))
let
materialLayer
:
MaterialLayer
=
MaterialLayer
(
frame
:
CGRectMake
(
132
,
132
,
150
,
150
))
materialLayer
.
image
=
UIImage
(
named
:
"CosmicMindAppIcon"
)
materialLayer
.
shape
=
.
Circle
materialLayer
.
shape
=
.
Circle
materialLayer
.
depth
=
.
Depth2
materialLayer
.
depth
=
.
Depth2
UIImage
.
contentsOfURL
(
NSURL
(
string
:
"http://www.cosmicmind.io/CosmicMind.png"
)
!
)
{
(
image
:
UIImage
?,
error
:
NSError
?)
in
if
let
v
:
UIImage
=
image
{
materialLayer
.
image
=
v
}
else
{
materialLayer
.
image
=
UIImage
(
named
:
"CosmicMindAppIcon"
)
}
}
// Add materialLayer to UIViewController.
// Add materialLayer to UIViewController.
view
.
layer
.
addSublayer
(
materialLayer
)
view
.
layer
.
addSublayer
(
materialLayer
)
...
...
Sources/Material+UIImage+Network.swift
View file @
bec6cbeb
...
@@ -32,16 +32,20 @@ import UIKit
...
@@ -32,16 +32,20 @@ import UIKit
public
extension
UIImage
{
public
extension
UIImage
{
/**
/**
:name: contentsOfURL
Asynchronously load images with a completion block.
- Parameter URL: A URL destination to fetch the image from.
- Parameter completion: A completion block that is executed once the image
has been retrieved.
*/
*/
public
class
func
contentsOfURL
(
URL
:
NSURL
,
completion
:
((
image
:
UIImage
?,
error
:
NSError
?)
->
Void
))
{
public
class
func
contentsOfURL
(
URL
:
NSURL
,
completion
:
((
image
:
UIImage
?,
error
:
NSError
?)
->
Void
))
{
let
request
:
NSURLRequest
=
NSURLRequest
(
URL
:
URL
)
NSURLSession
.
sharedSession
()
.
dataTaskWithRequest
(
NSURLRequest
(
URL
:
URL
))
{
(
data
:
NSData
?,
response
:
NSURLResponse
?,
error
:
NSError
?)
in
NSURLConnection
.
sendAsynchronousRequest
(
request
,
queue
:
NSOperationQueue
.
mainQueue
())
{
(
response
:
NSURLResponse
?,
data
:
NSData
?,
error
:
NSError
?)
->
Void
in
dispatch_async
(
dispatch_get_main_queue
())
{
if
let
v
:
NSError
=
error
{
if
let
v
:
NSError
=
error
{
completion
(
image
:
nil
,
error
:
v
)
completion
(
image
:
nil
,
error
:
v
)
}
else
if
let
v
:
NSData
=
data
{
}
else
if
let
v
:
NSData
=
data
{
completion
(
image
:
UIImage
(
data
:
v
),
error
:
nil
)
completion
(
image
:
UIImage
(
data
:
v
),
error
:
nil
)
}
}
}
}
}
.
resume
()
}
}
}
}
\ No newline at end of file
Sources/Material+UIImage.swift
View file @
bec6cbeb
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
import
UIKit
import
UIKit
public
enum
Content
ImageFormatType
{
public
enum
ImageFormatType
{
case
PNG
case
PNG
case
JPEG
case
JPEG
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment