在我的应用程序中,我将UITextView设置为UITableViewCell的contentView,以便您可以写入它。这就是我设置它的方式:
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(cell.bounds.origin.x, cell.bounds.origin.y, cell.contentView.frame.size.width, cell.contentView.frame.size.height)];
[textView setFont:[UIFont fontWithName:@"Arial" size:18.0f]];
[textView setBackgroundColor:[UIColor blueColor]];
[textView setAutocorrectionType:UITextAutocorrectionTypeNo];
textView.text = cell.textLabel.text;
textView.delegate = self;
cell.textLabel.text = @"";
self.textView = textView;
[cell.contentView addSubview:textView];
[textView becomeFirstResponder];
我想将textView.text
设置在cell.textlabel.text
所在的位置,但是它稍微向前,然后是单元格文本。如何将单元格的文本对齐方式和/或文本偏移量设置为UITextView,以便文本位于同一位置?
答案 0 :(得分:0)
yourUITextView.contentInset = UIEdgeInsetsMake(-4,-8,0,0); // Mess around with these values
或者...
设置textView的框架
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(5, 0, cell.contentView.frame.size.width - 10, cell.contentView.frame.size.height)];