-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from analogcode/dev
Add watermarked image for share activity by @CamMcLeod
- Loading branch information
Showing
7 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// LogoShareView.swift | ||
// SwiftRadio | ||
// | ||
// Created by Cameron Mcleod on 2019-07-12. | ||
// Copyright © 2019 matthewfecher.com. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class LogoShareView: UIView { | ||
|
||
@IBOutlet weak var albumArtImageView: UIImageView! | ||
@IBOutlet weak var radioShoutoutLabel: UILabel! | ||
@IBOutlet weak var trackTitleLabel: UILabel! | ||
@IBOutlet weak var trackArtistLabel: UILabel! | ||
@IBOutlet weak var logoImageView: UIImageView! | ||
|
||
class func instanceFromNib() -> LogoShareView { | ||
return UINib(nibName: "LogoShareView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! LogoShareView | ||
} | ||
|
||
func shareSetup(albumArt : UIImage, radioShoutout: String, trackTitle: String, trackArtist: String) { | ||
self.albumArtImageView.image = albumArt | ||
self.radioShoutoutLabel.text = radioShoutout | ||
self.trackTitleLabel.text = trackTitle | ||
self.trackArtistLabel.text = trackArtist | ||
self.logoImageView.image = UIImage(named: "logo") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> | ||
<device id="retina6_1" orientation="portrait"> | ||
<adaptation id="fullscreen"/> | ||
</device> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="LogoShareView" customModule="SwiftRadio" customModuleProvider="target"> | ||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="sgO-Os-qNc" userLabel="Main Stack"> | ||
<rect key="frame" x="8" y="8" width="584" height="584"/> | ||
<subviews> | ||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="zmo-M8-m9o" userLabel="Album Art"> | ||
<rect key="frame" x="0.0" y="0.0" width="584" height="435"/> | ||
<constraints> | ||
<constraint firstAttribute="height" constant="435" id="odw-Xz-Dzz"/> | ||
</constraints> | ||
</imageView> | ||
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="tPe-Vc-KR3" userLabel="Track Info"> | ||
<rect key="frame" x="0.0" y="455" width="584" height="88"/> | ||
<subviews> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ptC-tD-gdN" userLabel="Title"> | ||
<rect key="frame" x="0.0" y="0.0" width="181.5" height="88"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
<color key="textColor" cocoaTouchSystemColor="lightTextColor"/> | ||
<color key="highlightedColor" cocoaTouchSystemColor="lightTextColor"/> | ||
</label> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UhH-FP-Yas" userLabel="Artist"> | ||
<rect key="frame" x="201.5" y="0.0" width="181" height="88"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
<color key="textColor" cocoaTouchSystemColor="lightTextColor"/> | ||
<color key="highlightedColor" cocoaTouchSystemColor="lightTextColor"/> | ||
</label> | ||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Wb0-C0-hGr" userLabel="Logo"> | ||
<rect key="frame" x="402.5" y="0.0" width="181.5" height="88"/> | ||
</imageView> | ||
</subviews> | ||
</stackView> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LsP-Sq-acL" userLabel="Radio Shoutout"> | ||
<rect key="frame" x="0.0" y="563" width="584" height="21"/> | ||
<constraints> | ||
<constraint firstAttribute="height" constant="21" id="gRG-0o-oJ8"/> | ||
</constraints> | ||
<fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
<color key="textColor" cocoaTouchSystemColor="lightTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
</stackView> | ||
</subviews> | ||
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | ||
<constraints> | ||
<constraint firstItem="sgO-Os-qNc" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="8" id="Mtg-2A-d5g"/> | ||
<constraint firstItem="sgO-Os-qNc" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="8" id="PAp-lT-AWa"/> | ||
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="sgO-Os-qNc" secondAttribute="trailing" constant="8" id="Ydx-tF-aHS"/> | ||
<constraint firstAttribute="bottom" secondItem="sgO-Os-qNc" secondAttribute="bottom" constant="8" id="f80-X9-fsP"/> | ||
</constraints> | ||
<nil key="simulatedTopBarMetrics"/> | ||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/> | ||
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/> | ||
<connections> | ||
<outlet property="albumArtImageView" destination="zmo-M8-m9o" id="UAh-AN-ANo"/> | ||
<outlet property="logoImageView" destination="Wb0-C0-hGr" id="P1S-1A-jy7"/> | ||
<outlet property="radioShoutoutLabel" destination="LsP-Sq-acL" id="o6j-gY-1Wg"/> | ||
<outlet property="trackArtistLabel" destination="UhH-FP-Yas" id="NR4-tS-aF6"/> | ||
<outlet property="trackTitleLabel" destination="ptC-tD-gdN" id="EHQ-oR-a74"/> | ||
</connections> | ||
</view> | ||
</objects> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// ShareImageCreator.swift | ||
// SwiftRadio | ||
// | ||
// Created by Fethi El Hassasna on 2019-08-20. | ||
// Copyright © 2019 matthewfecher.com. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class ShareImageGenerator { | ||
|
||
private let radioShoutout: String | ||
private let track: Track | ||
|
||
init(radioShoutout: String, track: Track) { | ||
self.radioShoutout = radioShoutout | ||
self.track = track | ||
} | ||
|
||
func generate() -> UIImage { | ||
let logoShareView = LogoShareView.instanceFromNib() | ||
let songToShare = radioShoutout | ||
|
||
logoShareView.shareSetup(albumArt: track.artworkImage ?? #imageLiteral(resourceName: "albumArt"), radioShoutout: songToShare, trackTitle: track.title, trackArtist: track.artist) | ||
|
||
UIGraphicsBeginImageContextWithOptions(CGSize(width: logoShareView.frame.width, height: logoShareView.frame.height), true, 0) | ||
logoShareView.drawHierarchy(in: logoShareView.frame, afterScreenUpdates: true) | ||
let shareImage = UIGraphicsGetImageFromCurrentImageContext() | ||
UIGraphicsEndImageContext() | ||
|
||
return shareImage ?? track.artworkImage ?? #imageLiteral(resourceName: "albumArt") | ||
} | ||
} |