繁体   English   中英

用UITextView替换UITableViewCell文本

[英]Replace UITableViewCell text with UITextView

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

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)];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM