Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AF7BB31E195C749600E46AF2"
BuildableName = "CharacterText.app"
BlueprintName = "CharacterText"
ReferencedContainer = "container:CharacterText.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AF7BB330195C749600E46AF2"
BuildableName = "CharacterTextTests.xctest"
BlueprintName = "CharacterTextTests"
ReferencedContainer = "container:CharacterText.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AF7BB330195C749600E46AF2"
BuildableName = "CharacterTextTests.xctest"
BlueprintName = "CharacterTextTests"
ReferencedContainer = "container:CharacterText.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AF7BB31E195C749600E46AF2"
BuildableName = "CharacterText.app"
BlueprintName = "CharacterText"
ReferencedContainer = "container:CharacterText.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AF7BB31E195C749600E46AF2"
BuildableName = "CharacterText.app"
BlueprintName = "CharacterText"
ReferencedContainer = "container:CharacterText.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AF7BB31E195C749600E46AF2"
BuildableName = "CharacterText.app"
BlueprintName = "CharacterText"
ReferencedContainer = "container:CharacterText.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>CharacterText.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>AF7BB31E195C749600E46AF2</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>AF7BB330195C749600E46AF2</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
41 changes: 41 additions & 0 deletions CharacterText.xcworkspace/xcshareddata/CharacterText.xccheckout
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>3217EBBE-11A0-4C10-9972-D779A8AC3569</string>
<key>IDESourceControlProjectName</key>
<string>CharacterText</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>B762B879E1986148CFB9935B4BCC2FFABE987B82</key>
<string>github.com:NatashaTheRobot/CharacterText.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>CharacterText.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>B762B879E1986148CFB9935B4BCC2FFABE987B82</key>
<string>..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>github.com:NatashaTheRobot/CharacterText.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>B762B879E1986148CFB9935B4BCC2FFABE987B82</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>B762B879E1986148CFB9935B4BCC2FFABE987B82</string>
<key>IDESourceControlWCCName</key>
<string>CharacterText</string>
</dict>
</array>
</dict>
</plist>
Binary file not shown.
74 changes: 39 additions & 35 deletions CharacterText/Classes/CharacterLabel/CharacterLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CharacterLabel: UILabel, NSLayoutManagerDelegate {
}

set {
let wordRange = NSMakeRange(0, newValue.utf16count)
let wordRange = NSMakeRange(0, newValue.utf16Count)
var attributedText = NSMutableAttributedString(string: newValue)
attributedText.addAttribute(NSForegroundColorAttributeName , value:self.textColor, range:wordRange)
attributedText.addAttribute(NSFontAttributeName , value:self.font, range:wordRange)
Expand Down Expand Up @@ -92,10 +92,15 @@ class CharacterLabel: UILabel, NSLayoutManagerDelegate {

}

init(frame: CGRect) {
override init(frame: CGRect) {
super.init(frame: frame)
setupLayoutManager()
}

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupLayoutManager()
}

override func awakeFromNib() {
super.awakeFromNib()
Expand All @@ -117,41 +122,40 @@ class CharacterLabel: UILabel, NSLayoutManagerDelegate {

func calculateTextLayers() {
characterTextLayers.removeAll(keepCapacity: false)
if let attributedText = textStorage.string? {

let wordRange = NSMakeRange(0, attributedText.utf16count);
let attributedString = self.internalAttributedText();
let layoutRect = layoutManager.usedRectForTextContainer(textContainer);
let attributedText = textStorage.string

let wordRange = NSMakeRange(0, attributedText.utf16Count)
let attributedString = self.internalAttributedText()
let layoutRect = layoutManager.usedRectForTextContainer(textContainer)

for var index = wordRange.location; index < wordRange.length+wordRange.location; index += 0 {
let glyphRange = NSMakeRange(index, 1);
let characterRange = layoutManager.characterRangeForGlyphRange(glyphRange, actualGlyphRange:nil);
let textContainer = layoutManager.textContainerForGlyphAtIndex(index, effectiveRange: nil)
var glyphRect = layoutManager.boundingRectForGlyphRange(glyphRange, inTextContainer: textContainer!)
var location = layoutManager.locationForGlyphAtIndex(index)
var kerningRange = layoutManager.rangeOfNominallySpacedGlyphsContainingIndex(index);

for var index = wordRange.location; index < wordRange.length+wordRange.location; index += 0 {
let glyphRange = NSMakeRange(index, 1);
let characterRange = layoutManager.characterRangeForGlyphRange(glyphRange, actualGlyphRange:nil);
let textContainer = layoutManager.textContainerForGlyphAtIndex(index, effectiveRange: nil);
var glyphRect = layoutManager.boundingRectForGlyphRange(glyphRange, inTextContainer: textContainer);
var location = layoutManager.locationForGlyphAtIndex(index);
var kerningRange = layoutManager.rangeOfNominallySpacedGlyphsContainingIndex(index);

if kerningRange.length > 1 && kerningRange.location == index {
if countElements(characterTextLayers) > 0 {
var previousLayer = characterTextLayers[characterTextLayers.endIndex-1]
var frame = previousLayer.frame
frame.size.width += CGRectGetMaxX(glyphRect)-CGRectGetMaxX(frame)
previousLayer.frame = frame
}
if kerningRange.length > 1 && kerningRange.location == index {
if countElements(characterTextLayers) > 0 {
var previousLayer = characterTextLayers[characterTextLayers.endIndex-1]
var frame = previousLayer.frame
frame.size.width += CGRectGetMaxX(glyphRect)-CGRectGetMaxX(frame)
previousLayer.frame = frame
}


glyphRect.origin.y += location.y-(glyphRect.height/2)+(self.bounds.size.height/2)-(layoutRect.size.height/2);


var textLayer = CATextLayer(frame: glyphRect, string: attributedString.attributedSubstringFromRange(characterRange));
initialTextLayerAttributes(textLayer)

layer.addSublayer(textLayer);
characterTextLayers.append(textLayer);

index += characterRange.length;
}


glyphRect.origin.y += location.y-(glyphRect.height/2)+(self.bounds.size.height/2)-(layoutRect.size.height/2);


var textLayer = CATextLayer(frame: glyphRect, string: attributedString.attributedSubstringFromRange(characterRange));
initialTextLayerAttributes(textLayer)

layer.addSublayer(textLayer);
characterTextLayers.append(textLayer);

index += characterRange.length;
}
}

Expand All @@ -160,7 +164,7 @@ class CharacterLabel: UILabel, NSLayoutManagerDelegate {
}

func internalAttributedText() -> NSMutableAttributedString! {
let wordRange = NSMakeRange(0, textStorage.string.utf16count);
let wordRange = NSMakeRange(0, textStorage.string.utf16Count)
var attributedText = NSMutableAttributedString(string: textStorage.string);
attributedText.addAttribute(kCTForegroundColorAttributeName , value:self.textColor.CGColor, range:wordRange);
attributedText.addAttribute(kCTFontAttributeName , value:self.font, range:wordRange);
Expand Down
9 changes: 7 additions & 2 deletions CharacterText/Classes/CharacterLabel/CharacterTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ class CharacterTextView: UITextView, NSLayoutManagerDelegate {

}

init(frame: CGRect, textContainer: NSTextContainer!) {
override init(frame: CGRect, textContainer: NSTextContainer!) {
super.init(frame: frame, textContainer: textContainer);
setupLayoutManager();
}

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupLayoutManager()
}

override func awakeFromNib() {
super.awakeFromNib();
Expand All @@ -68,7 +73,7 @@ class CharacterTextView: UITextView, NSLayoutManagerDelegate {
let glyphRange = NSMakeRange(index, 1);
let characterRange = layoutManager.characterRangeForGlyphRange(glyphRange, actualGlyphRange:nil);
let textContainer = layoutManager.textContainerForGlyphAtIndex(index, effectiveRange: nil);
var glyphRect = layoutManager.boundingRectForGlyphRange(glyphRange, inTextContainer: textContainer);
var glyphRect = layoutManager.boundingRectForGlyphRange(glyphRange, inTextContainer: textContainer!);
var location = layoutManager.locationForGlyphAtIndex(index);
var kerningRange = layoutManager.rangeOfNominallySpacedGlyphsContainingIndex(index);

Expand Down
7 changes: 6 additions & 1 deletion CharacterText/Classes/Flickr/FlickrCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ class FlickrCollectionViewCell: UICollectionViewCell {
var photoImageView: UIImageView!
var darkenMask: UIView!

init(frame: CGRect) {
override init(frame: CGRect) {
super.init(frame: frame)
initialSetup()
}

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialSetup()
}

override func awakeFromNib() {
super.awakeFromNib()
Expand Down
2 changes: 1 addition & 1 deletion CharacterText/Classes/Utilities/CLMLayerAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CLMLayerAnimation: NSObject {
}

if animations.count > 0 {
animationGroup = CAAnimationGroup()
animationGroup = CAAnimationGroup() as CAAnimationGroup
animationGroup!.animations = animations
}

Expand Down
11 changes: 5 additions & 6 deletions CharacterText/Classes/ViewControllers/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

@IBOutlet var collectionView: UICollectionView
@IBOutlet var collectionView: UICollectionView!
var dataArray = Array<FlickrPhoto>()
var characterLabel: MotionLabel!;

Expand All @@ -26,7 +26,7 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
FlickrKit.sharedFlickrKit().initializeWithAPIKey("334626934a41897193b6a0613f1c94a0", sharedSecret: "b0132e5cfd44574b")
let flickrKit = FlickrKit.sharedFlickrKit()
flickrKit.call(FKFlickrInterestingnessGetList()) { response, error in
if response {
if let response = response {
var photoUrls = Array<FlickrPhoto>()
var photos: NSDictionary = response["photos"] as NSDictionary;
var photoArray: NSArray = photos["photo"] as NSArray;
Expand Down Expand Up @@ -54,13 +54,12 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
characterLabel.text = "You"
self.view.addSubview(characterLabel)
}

func collectionView(collectionView: UICollectionView!, numberOfItemsInSection section: Int) -> Int {
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return dataArray.count
}

func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell
{
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var collectionViewCell : FlickrCollectionViewCell! = collectionView.dequeueReusableCellWithReuseIdentifier("FlickrCollectionViewCell", forIndexPath: indexPath) as FlickrCollectionViewCell

collectionViewCell.configure(dataArray[indexPath.row])
Expand Down
Loading