Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.
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
21 changes: 20 additions & 1 deletion Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0920;
TargetAttributes = {
F18E158F1C0E36830038FFD3 = {
CreatedOnToolsVersion = 7.1.1;
Expand Down Expand Up @@ -182,13 +182,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -226,13 +234,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -251,6 +267,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -263,6 +280,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.example.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -274,6 +292,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.example.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
33 changes: 0 additions & 33 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,10 @@ import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

let controller = ViewController()
let navigationController = UINavigationController(rootViewController: controller)

self.window?.rootViewController = navigationController

return true
}

func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

15 changes: 15 additions & 0 deletions Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -29,6 +39,11 @@
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
37 changes: 31 additions & 6 deletions Example/Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="cHS-hI-EIt">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<navigationItem key="navigationItem" id="FK3-Cb-qmR"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="372" y="32.833583208395808"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="pzG-Uk-Deo">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="cHS-hI-EIt" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="HO8-d9-5xa">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="Pzu-vO-yur"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="jND-TW-voR" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-412" y="33"/>
</scene>
</scenes>
</document>
28 changes: 9 additions & 19 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,20 @@ import UIKit

class ViewController: UIViewController, UITextViewDelegate {

var textView : VerticalTextView!
var textView: VerticalTextView!

override func viewDidLoad() {
super.viewDidLoad()
title = "VerticalTextView"

self.title = "VerticalTextView"
textView = VerticalTextView(frame: view.bounds)
textView.delegate = self
textView.font = UIFont.systemFont(ofSize: 14)
textView.textColor = UIColor.black
textView.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed fermentum massa eu pulvinar fermentum."
textView.verticalAlignment = .middle

self.textView = VerticalTextView(frame: self.view.bounds)
self.textView.delegate = self
self.textView.font = UIFont.systemFontOfSize(14)
self.textView.textColor = UIColor.blackColor()

self.textView.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed fermentum massa eu pulvinar fermentum."

self.textView.verticalAlignment = .Middle

self.view.addSubview(self.textView)
// Do any additional setup after loading the view, typically from a nib.
view.addSubview(textView)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}

37 changes: 19 additions & 18 deletions Source/VerticalTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,40 @@ import UIKit

class VerticalTextView: UITextView {

enum VerticalAlignment: Int {
case Top = 0, Middle, Bottom
enum VerticalAlignment {
case top
case middle
case bottom
}

var verticalAlignment: VerticalAlignment = .Middle
var verticalAlignment: VerticalAlignment = .middle

//override contentSize property and observe using didSet
// Override contentSize property and observe using didSet
override var contentSize: CGSize {
didSet {
let height = self.bounds.size.height
let contentHeight: CGFloat = contentSize.height
let height = bounds.size.height
let contentHeight = contentSize.height
var topCorrect: CGFloat = 0.0

switch (self.verticalAlignment) {
case .Top:
self.contentOffset = CGPointZero //set content offset to top
switch verticalAlignment {
case .top:
contentOffset = .zero //set content offset to top

case .Middle:
topCorrect = (height - contentHeight * self.zoomScale) / 2.0
case .middle:
topCorrect = (height - contentHeight * zoomScale) / 2.0
topCorrect = topCorrect < 0 ? 0 : topCorrect
self.contentOffset = CGPoint(x: 0, y: -topCorrect)
contentOffset = CGPoint(x: 0, y: -topCorrect)

case .Bottom:
case .bottom:
topCorrect = self.bounds.size.height - contentHeight
topCorrect = topCorrect < 0 ? 0 : topCorrect
self.contentOffset = CGPoint(x: 0, y: -topCorrect)
contentOffset = CGPoint(x: 0, y: -topCorrect)
}

if contentHeight >= height { // if the contentSize is greater than the height
topCorrect = contentHeight - height // set the contentOffset to be the
topCorrect = topCorrect < 0 ? 0 : topCorrect // contentHeight - height of textView
self.contentOffset = CGPoint(x: 0, y: topCorrect)
contentOffset = CGPoint(x: 0, y: topCorrect)
}
}
}
Expand All @@ -63,9 +65,8 @@ class VerticalTextView: UITextView {

override func layoutSubviews() {
super.layoutSubviews()

let size = self.contentSize // forces didSet to be called
self.contentSize = size
contentSize = size
}

}
}