首页 文章

使用动态类型更改用户选择的字体大小和权重时,TableView中UITextField的垂直对齐方式错误

提问于
浏览
0

当使用动态类型更改用户选择的字体大小和权重时,我在TableView中垂直对齐UITextField时遇到问题 .

我可怕的英语原因,我将使用截图:Upps,没有足够的声誉发布它们 . :-(

在我的TableView中使用自定义单元我使用Autolayout . 但禁用Autolayout对我的问题无关紧要 . 所以我认为这不会导致它 .

一切都很好看 .

当我更改为“设置”并选择另一个字体大小后,返回到应用程序后,UITextFields垂直对齐已向上移动约5个点,具体取决于新的字体大小

当一个 [textField becomeFirstResponder] 时,它会移动到正确的位置:

When I close the Form and open it again, everything is ok!!!

源代码:

in viewDidLoad

[[NSNotificationCenter defaultCenter]
        addObserver:self
        selector:@selector(preferredContentSizeChanged:)
        name:UIContentSizeCategoryDidChangeNotification
        object:nil];

- (void)preferredContentSizeChanged:(NSNotification *)notification 
{
[self.tableView reloadData];
}  

- (void) configureFonts:(DetailColumnCell *)cell 
{
cell.txtDetail.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
}

好的,一个小问题,但所以看起来不专业;-)

编辑1

TextField上方有一个Label . 此标签的对齐保持良好 .

编辑2

当在TableView中底部是不可见的单元格时,我更改了Font并滚动到此前不可见的单元格,这些单元格没问题! reuse 细胞是问题吗?但我认为没办法改变这个......

1 回答

  • 0

    Urrgh,我在this article几天后找到了它:-)

    我不得不添加方法 estimatedHeightForRowAtIndexPath 并且everythig很好:

    (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {

    // Do the minimal calculations required to be able to return an estimated row height that's
        // within an order of magnitude of the actual height.
        // 250 => try and error: 200.0 was enough for me at iPhone, but iPad need more
        return 250.0f;
    

相关问题