【问题标题】:Frame width has strange behaviour帧宽有奇怪的行为
【发布时间】:2010-10-22 08:45:27
【问题描述】:

我想在我的 gouped 表格视图中添加一个页脚视图 现在我有这个:

NSLog(@"width:%f",self.view.frame.size.width);
        UILabel *lblInfo = [[UILabel alloc] initWithFrame:CGRectMake(50, 30,self.view.frame.size.width - 100, 70)];
        lblInfo.text = @"Hellow";
        [footerView addSubview:lblInfo];
        [lblInfo release];

这给了我这个结果:http://img256.imageshack.us/i/schermafbeelding2010102t.png/ 这是风景,self.view 是我的 splitcontrol 的详细视图的推送子视图。 第一个的nslog:->width: 703

如果我转向(纵向),我会得到这个结果:http://img821.imageshack.us/i/schermafbeelding2010102.png/ 第二个的nslog:-> width: 768

通常两个页脚视图的左右边距应为 50px...

我在监督什么?

【问题讨论】:

    标签: iphone uitableview size ipad uisplitviewcontroller


    【解决方案1】:

    你应该设置autoresizingMask

    lblInfo.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
    

    您还应该注意创建带有页脚大小的标签:

    UILabel *lblInfo = [[UILabel alloc] initWithFrame:CGRectMake(50, 30,footerView.frame.size.width - 100, 70)];
    

    【讨论】:

    • 这相当于你在 Interface Builder 中,在检查器的 size 部分中所做的。
    • 哇不知道 :) 什么是 |字符?和“或”一样吗?我试过了,但现在我得到了这个结果:yfrog.com/5oschermafbeelding2010102p(所以我仍然不在那里)
    • 在您的示例中,footerViewself.view 的宽度是否相同?创建标签时,请尝试使用 footerView.frame.size.width - 100 作为宽度来创建它。
    • 刚刚添加:footerView.frame = CGRectMake(50, 30,self.view.frame.size.width - 100, 70);还是一样