1

在我的应用程序中,我将 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,以便文本位于同一位置?

4

1 回答 1

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)];
于 2012-12-05T13:26:14.330 回答