开发者

Frame width has strange behaviour

开发者 https://www.devze.com 2023-01-21 16:46 出处:网络
I want to add a footer view to my gouped table view for now i have this: NSLog(@\"width:%f\",self.view.frame.size.width);

I want to add a footer view to my gouped table view for now i have this:

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];

which give me this result: http://img256.imageshack.us/i/schermafbeelding2010102t.png/ This is landscape and self.view is an pushed subview of the detailview of my splitcontrol. The nslog of the first: ->width: 703

If i turn (to portrait) it i get this result:http://img821.imageshack.us/i/s开发者_StackOverflow社区chermafbeelding2010102.png/ The nslog of the second: -> width: 768

normally the two footer views should have a left & right margin of 50px...

What am i overseeing?


You should set autoresizingMask:

lblInfo.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;

You should also note to create the label with the footer's size:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号