customtextview's People
customtextview's Issues
placeholderLabel.frame.size.width
override var font: UIFont? {
didSet {
print("didiSet: \(font)")
placeholderLabel.font = font
placeholderLabel.frame.size.width = textContainer.size.width - 4
print(textContainer.size)
placeholderLabel.sizeToFit()
}
}
4って何?
ここもinset考慮する必要ない?
placeholderLabelの左端と右端はinsetの距離とあってる必要がある気がする
課題
UITextViewの課題として複数あげられるのが、
placeholder
がない- キーボードを閉じる機能がデフォルトで存在しない
の2点があげられる。
この二つの機能をデフォルトで持つカスタムキーボードをまずは作成してみよう。
設計とか、こういう感じで実装しようと思ってる、見たいのがあればこのissueで議論
placeholderno設定
@IBInspectable var placeholder: String? {
didSet {
print("placeholder did set.")
placeholderLabel.text = placeholder
// 表示可能最大行数を指定(0 -> 行数は可変)
placeholderLabel.numberOfLines = 0
placeholderLabel.sizeToFit()
// 単語の途中で改行されないようにする
placeholderLabel.lineBreakMode = .byWordWrapping
}
}
ライブラリの説明
Simple customizable UITextView subclass add placeholder and accsesaryBar
これ英語的におかしいだろ
せめてhavingとかaddedとかの形容詞化させるかdefault ~とかのキーワードの方がよくない?
podライブラリの作成
Using Pod Lib Create
Making a CocoaPod
podで作成する手順。ざっとみといて。とりあえず名前考えてから。
textContainerInset変更時の処理
override var textContainerInset: UIEdgeInsets {
didSet {
print("didiSet: \(textContainerInset)")
placeholderLabel.frame.origin = CGPoint(x: textContainerInset.left + 2, y: textContainerInset.top)
print(self.frame)
// print(placeholderLabel.textRect(forBounds: self.frame, limitedToNumberOfLines: 4))
}
}
CGPoint(x: textContainerInset.left + 2, y: textContainerInset.top)
ってやってるけど、普通に
xがtextContainerInset.left分
yがtextContainerInset.top分だけずれるのが普通じゃない?
x = placeholderLabel.frame.origin + textContainerInset.leftみたいな
inspectable properties
- Boolean
- Integer or floating point number
- String
- Localized string
- Rectangle
- Point
- Size
- Color
- Range
- Nil
以上のプロパティはIBで値を設定することができるので、設定しよう
NotificationCenter.defaultの取得
毎回NotificationCenter.defaultでアクセスするの、ちょっと冗長だから
private let notificatin = NotificationCenter.default
定義してもいいかも
textContainerInset変更時のplaceholderのレイアウト
textContainerInsetのtop以外の変更に対応できていない。
TextViewのテキストサイズに伴って、Placeholderラベルの表示位置を変動させる
キーボードを閉じる機能をデフォルトで実装する
アクセス修飾子
今回のプロジェクトは意識しなくていいけど、ライブラリとしてフレームワークを作成する時は、
public
,open
ここら辺のアクセス修飾子を意識する必要があるから調べといて
ライブラリ名
そろそろライブラリ名も考えたほうが良いかな。
役割わかりやすい名前
- CustomizableTextView
- SimpleCustomizableTextView
まあ役割がわかりやすい名前が無難かな。でもPlaceholderTextViewとか限定的な名前にしちゃうと、拡張性がないからある程度今後も機能をつけたせれるような名前がいいかな
prefixを入れる
- KSTextView
自分の名前をprefixに入れる場合もあるけど、これはobjective-Cの名残でswiftぽくないから微妙
完全に関係のない名前
- Udon
- Soba
- Monkey
自分の好きな動物とか地名とか食べ物を名前にする場合もある。結構いけてるライブラリはこういうのがあるけど、最初だし簡易的なライブラリだからあえてここら辺をやr必要はないかなという感触
storyboardでの生成時のplaceholderの初期化
storyboardで生成した際、初めの画面が出たときにtextとplaceholderが共存する。
Customize propaties
- アクセサリビューの色
- アクセサリビューのテキスト
- アクセサリビューのDoneボタンのテキストフォント
まあとりあえず最低限これは変えられるようにしたいかな
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.