2012-12-05 112 views
1

在我的應用程序中,我將UITextView設置爲UITableViewCell的contentView,以便您可以寫入它。這是我的設置:用UITextView替換UITableViewCell文本

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

感謝了很多,幾乎沒有的伎倆。我可以得到正確的垂直對齊方式,但無論我嘗試向左還是向右嘗試哪些值都沒有什麼不同。任何想法爲什麼? – illogic

+0

您是否試圖將文本從視圖的左側稍微向右移動? –

+0

是的,我願意。我不想改變框架的大小,因爲這會搞亂我的'heightForRowAtIndexPath'返回值:/ – illogic