Code Monkey home page Code Monkey logo

customtextview's People

Contributors

shoheiyokoyama avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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 ~とかのキーワードの方がよくない?

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みたいな

NotificationCenter.defaultの取得

毎回NotificationCenter.defaultでアクセスするの、ちょっと冗長だから

private let notificatin = NotificationCenter.default

定義してもいいかも

アクセス修飾子

今回のプロジェクトは意識しなくていいけど、ライブラリとしてフレームワークを作成する時は、
public,openここら辺のアクセス修飾子を意識する必要があるから調べといて

ライブラリ名

そろそろライブラリ名も考えたほうが良いかな。

役割わかりやすい名前

  • CustomizableTextView
  • SimpleCustomizableTextView

まあ役割がわかりやすい名前が無難かな。でもPlaceholderTextViewとか限定的な名前にしちゃうと、拡張性がないからある程度今後も機能をつけたせれるような名前がいいかな

prefixを入れる

  • KSTextView

自分の名前をprefixに入れる場合もあるけど、これはobjective-Cの名残でswiftぽくないから微妙

完全に関係のない名前

  • Udon
  • Soba
  • Monkey

自分の好きな動物とか地名とか食べ物を名前にする場合もある。結構いけてるライブラリはこういうのがあるけど、最初だし簡易的なライブラリだからあえてここら辺をやr必要はないかなという感触

Customize propaties

  • アクセサリビューの色
  • アクセサリビューのテキスト
  • アクセサリビューのDoneボタンのテキストフォント

まあとりあえず最低限これは変えられるようにしたいかな

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.