我有一个嵌入在分组表视图单元格中的UITextView,我似乎无法在轮换时更新。当它变成风景时,它基本上保持相同的宽度(假定的肖像),导致大约40%的视图在左侧是空白的。
有没有办法轻松更新?我在看willRotateToInterfaceOrientation
,但我不确定更新旋转视图是否正确。
具体来说,我认为应该更新宽度值,因为它是基于宽度的。
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;
}
}
}
答案 0 :(得分:4)
您需要设置textField.autoresizingMask = UIViewAutoresizingFlexibleWidth
,它会在视图大小更改时拉伸对象的宽度。
答案 1 :(得分:0)
您是否已尝试在IB中设置大小调整属性?应该能够在那里设置对象缩放的方式以及锚点。