【发布时间】:2015-01-04 02:59:28
【问题描述】:
当您键入时,我正在缩进 UITextView 中的第一行。这是一个演示。
这可行,但我不知道如何让文本视图在出现时缩进。如果您从键盘添加和删除一个字符,它会正确缩进空行,但当它第一次出现时我不知道如何执行此操作。
@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
【问题讨论】:
标签: objective-c ios8 uitextview