devxoul / UITextView-Placeholder

A missing placeholder for UITextView
MIT License
1.48k stars 259 forks source link

Padding #16

Closed akatreyt closed 8 years ago

akatreyt commented 9 years ago

I'm using this in a custom cell and would like to have the placeholder text have a x padding of 16. Any ways to get this done?

Thanks

devxoul commented 9 years ago

Currently there's no way to set only placeholder label's inset, because placeholder label is intended to follow textview's own text properties. You can set textContainerInset property of UITextView.

Alternatively, you can use textView.attributedPlaceholer to set NSAttributedString with attribute:

let paragraph = NSMutableParagraphStyle()
paragraph.firstLineHeadIndent = 20

let textView = UITextView()
textView.attributedText = NSAttributedString(
    string: "Hello, World!",
    attributes: [NSParagraphStyleAttributeName: paragraph]
)

screen shot 2015-10-21 at 3 46 12 pm