我在分组 TableView 单元格中嵌入了一个 UITextView,我似乎无法在旋转时更新。当它变成横向时,它基本上保持相同的宽度(假定为纵向),导致左侧大约 40% 的 View 是空白的。
有没有办法轻松更新这个?我在看 willRotateToInterfaceOrientation
但我不确定更新旋转 View 是否正确。
具体来说,我在想 宽度 值应该更新,因为它基于宽度。
if (indexPath.section == 1) {
switch (indexPath.row) {
case 0:
{
NSString *label = [self.pedal detail];
CGFloat width = [UIScreen mainScreen].bounds.size.width * .95;
CGSize stringSize = [label sizeWithFont:[UIFont systemFontOfSize:15]
constrainedToSize:CGSizeMake(320, 9999)
lineBreakMode:UILineBreakModeWordWrap];
UITextView *textField = [[UITextView alloc] init];
[textField setFrame:CGRectMake(50,0, width-10, stringSize.height+55)];
[textField setEditable:NO];
textField.backgroundColor = [UIColor clearColor];
textField.font = [UIFont systemFontOfSize:15];
textField.textAlignment = UITextAlignmentLeft;
cell.accessoryView = textField;
textField.text = [self.pedal detail];
[textField release];
break;
}
}
}
最佳答案
您需要设置textField.autoresizingMask = UIViewAutoresizingFlexibleWidth
,它在 View 大小变化时拉伸(stretch)对象的宽度。
更多信息请访问 UIView documentation
关于ios - 更改旋转时嵌入的 UITextView 宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9472471/