I'm indenting the first line in a UITextView
as you type. Here's a demo.
This works but I can't figure out how to have the text view indent when it appears. If you add and delete a character from the keyboard it indents the empty line correctly but I can't figure out how to do this when it first appears.
@interface ViewController ()
@property (strong, nonatomic) UITextView *textView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.textView = [UITextView new];
self.textView.delegate = self;
[self.view addSubview:self.textView];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.textView.frame = self.view.bounds;
[self textViewDidChange:self.textView];
}
- (void)textViewDidChange:(UITextView *)textView {
NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
style.firstLineHeadIndent = 20.f;
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:textView.text attributes:@{NSParagraphStyleAttributeName: style}];
textView.attributedText = string;
}
@end