Skip to content

Commit

Permalink
cocoa pods ready
Browse files Browse the repository at this point in the history
  • Loading branch information
cheebow committed Jul 24, 2015
1 parent 670c733 commit ec27fbd
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
7924E6411B61E77E00D3BBB0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7924E6401B61E77E00D3BBB0 /* Images.xcassets */; };
7924E6441B61E77E00D3BBB0 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7924E6421B61E77E00D3BBB0 /* LaunchScreen.xib */; };
7924E6501B61E77E00D3BBB0 /* PlaceholderTextViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7924E64F1B61E77E00D3BBB0 /* PlaceholderTextViewTests.swift */; };
7924E65C1B61E79300D3BBB0 /* PlaceholderTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7924E65B1B61E79300D3BBB0 /* PlaceholderTextView.swift */; };
796C8EFD1B62129D00EC4ACD /* PlaceholderTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 796C8EFC1B62129D00EC4ACD /* PlaceholderTextView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -37,7 +37,7 @@
7924E6491B61E77E00D3BBB0 /* PlaceholderTextViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PlaceholderTextViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7924E64E1B61E77E00D3BBB0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7924E64F1B61E77E00D3BBB0 /* PlaceholderTextViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaceholderTextViewTests.swift; sourceTree = "<group>"; };
7924E65B1B61E79300D3BBB0 /* PlaceholderTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlaceholderTextView.swift; sourceTree = "<group>"; };
796C8EFC1B62129D00EC4ACD /* PlaceholderTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PlaceholderTextView.swift; path = ../../Pod/Classes/PlaceholderTextView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -79,7 +79,7 @@
7924E6361B61E77E00D3BBB0 /* PlaceholderTextView */ = {
isa = PBXGroup;
children = (
7924E65B1B61E79300D3BBB0 /* PlaceholderTextView.swift */,
796C8EFC1B62129D00EC4ACD /* PlaceholderTextView.swift */,
7924E6391B61E77E00D3BBB0 /* AppDelegate.swift */,
7924E63B1B61E77E00D3BBB0 /* ViewController.swift */,
7924E63D1B61E77E00D3BBB0 /* Main.storyboard */,
Expand Down Expand Up @@ -215,7 +215,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7924E65C1B61E79300D3BBB0 /* PlaceholderTextView.swift in Sources */,
796C8EFD1B62129D00EC4ACD /* PlaceholderTextView.swift in Sources */,
7924E63C1B61E77E00D3BBB0 /* ViewController.swift in Sources */,
7924E63A1B61E77E00D3BBB0 /* AppDelegate.swift in Sources */,
);
Expand Down Expand Up @@ -413,6 +413,7 @@
7924E6551B61E77E00D3BBB0 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
7924E6561B61E77E00D3BBB0 /* Build configuration list for PBXNativeTarget "PlaceholderTextViewTests" */ = {
isa = XCConfigurationList;
Expand All @@ -421,6 +422,7 @@
7924E6581B61E77E00D3BBB0 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 5 additions & 8 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
The MIT License (MIT)

Copyright (c) 2015 Motokazu Sekine
Copyright (c) 2015 CHEEBOW <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -9,14 +7,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
30 changes: 30 additions & 0 deletions PlaceholderTextView.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Be sure to run `pod lib lint PlaceholderTextView.podspec' to ensure this is a
# valid spec and remove all comments before submitting the spec.
#
# Any lines starting with a # are optional, but encouraged
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = "PlaceholderTextView"
s.version = "0.1.0"
s.summary = "Add a placeholder to TextView."
s.description = <<-DESC
Add a placeholder to TextView.
DESC
s.homepage = "https://github.com/cheebow/PlaceholderTextView"
s.license = 'MIT'
s.author = { "CHEEBOW" => "[email protected]" }
s.source = { :git => "https://github.com/cheebow/PlaceholderTextView.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/cheebow'

s.platform = :ios, '8.0'
s.requires_arc = true

s.source_files = 'Pod/Classes/**/*'
s.resource_bundles = {
'PlaceholderTextView' => ['Pod/Assets/*.png']
}
end
Empty file added Pod/Assets/.gitkeep
Empty file.
Empty file added Pod/Classes/.gitkeep
Empty file.
120 changes: 120 additions & 0 deletions Pod/Classes/PlaceholderTextView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//
// PlaceholderTextView.swift
//
// Created by CHEEBOW on 2015/07/24.
// Copyright (c) 2015年 CHEEBOW. All rights reserved.
//

import UIKit

class PlaceholderTextView: UITextView {
let PLACEHOLDER_LEFT_MARGIN: CGFloat = 4.0
let PLACEHOLDER_TOP_MARGIN: CGFloat = 8.0

var placeholderLabel: UILabel = UILabel()

var _placeholderColor: UIColor = UIColor.lightGrayColor()
var placeholderColor: UIColor {
set {
_placeholderColor = newValue
self.placeholderLabel.textColor = self.placeholderColor
}
get {
return _placeholderColor
}
}

var _placeholder: String = ""
var placeholder: String {
set {
_placeholder = newValue
self.placeholderLabel.text = self.placeholder
self.placeholderSizeToFit()
}
get {
return _placeholder
}
}

override var text: String! {
set {
super.text = newValue
self.textChanged(nil)
}
get {
return super.text
}
}

override var font: UIFont! {
set {
super.font = newValue
self.placeholderLabel.font = newValue
self.placeholderSizeToFit()
}
get {
return super.font
}
}

private func placeholderSizeToFit() {
self.placeholderLabel.frame = CGRectMake(PLACEHOLDER_LEFT_MARGIN, PLACEHOLDER_TOP_MARGIN, self.frame.width - PLACEHOLDER_LEFT_MARGIN * 2, 0.0)
self.placeholderLabel.sizeToFit()
}

private func setup() {
self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
self.font = UIFont.systemFontOfSize(12.0)

self.placeholderLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
self.placeholderLabel.numberOfLines = 0
self.placeholderLabel.font = self.font
self.placeholderLabel.backgroundColor = UIColor.clearColor()
self.placeholderLabel.alpha = 1.0
self.placeholderLabel.tag = 999

self.placeholderLabel.textColor = self.placeholderColor
self.placeholderLabel.text = self.placeholder
self.placeholderSizeToFit()
self.addSubview(placeholderLabel)

self.sendSubviewToBack(placeholderLabel)

let center = NSNotificationCenter.defaultCenter()
center.addObserver(self, selector: "textChanged:", name: UITextViewTextDidChangeNotification, object: nil)

self.textChanged(nil)
}

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

override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
self.setup()
}

convenience init() {
self.init(frame: CGRectZero, textContainer: nil)
}

convenience init(frame: CGRect) {
self.init(frame: frame, textContainer: nil)
}

deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}

override func awakeFromNib() {
super.awakeFromNib()

self.setup()
}

func textChanged(notification:NSNotification?) {
self.viewWithTag(999)?.alpha = self.text.isEmpty ? 1.0 : 0.0
}
}
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# PlaceholderTextView
## Requirements

- Swift 1.2+
[![CI Status](http://img.shields.io/travis/CHEEBOW/PlaceholderTextView.svg?style=flat)](https://travis-ci.org/CHEEBOW/PlaceholderTextView)
[![Version](https://img.shields.io/cocoapods/v/PlaceholderTextView.svg?style=flat)](http://cocoapods.org/pods/PlaceholderTextView)
[![License](https://img.shields.io/cocoapods/l/PlaceholderTextView.svg?style=flat)](http://cocoapods.org/pods/PlaceholderTextView)
[![Platform](https://img.shields.io/cocoapods/p/PlaceholderTextView.svg?style=flat)](http://cocoapods.org/pods/PlaceholderTextView)

## Usage

To run the example project, clone the repo, and run `pod install` from the Example directory first.

```swift
let placeholderTextView = PlaceholderTextView()
let frame = CGRectMake(0.0, 20.0, 320.0, 100.0)
Expand All @@ -13,3 +17,24 @@ placeholderTextView.placeholder = "Placeholder Text"
placeholderTextView.placeholderColor = UIColor.lightGrayColor()
self.view.addSubview(placeholderTextView)
```

## Requirements

- Swift 1.2+

## Installation

PlaceholderTextView is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod "PlaceholderTextView"
```

## Author

CHEEBOW, [email protected]

## License

PlaceholderTextView is available under the MIT license. See the LICENSE file for more info.

0 comments on commit ec27fbd

Please sign in to comment.