简体   繁体   English

iOS版 - 无法对齐的UIScrollView UIViews

[英]iOS - Can't align UIViews in UIScrollView

I have UIViewController with UIScrollView and two labels and a button inside it: 我有带UIScrollView UIViewController和两个标签以及其中的一个按钮:

UIView
  -UIScrollView
    -UILabel
    -UILabel
    -UIButton

I need to align my UILabels and UIButton after each other dynamically, as every view can have different size. 我需要动态对齐我的UILabelsUIButton ,因为每个视图可以具有不同的大小。 UILabels are okay, but my UIButton goes into the middle of my second UILabel Here is my code: UILabels还好,但我UIButton进入我的第二中间UILabel这里是我的代码:

self.header.text = event.title;
self.header.numberOfLines = 0;
CGFloat headerHeight = [event.title sizeWithFont:[UIFont fontWithName:@"Arial" size:20] constrainedToSize:CGSizeMake(280, 100000) lineBreakMode:UILineBreakModeWordWrap].height;
self.header.frame = CGRectMake(19, 20, 280, headerHeight);

CGFloat positionY = 40 + [self.header.text sizeWithFont:[UIFont fontWithName:@"Arial" size:20] constrainedToSize:CGSizeMake(280, 100000) lineBreakMode:UILineBreakModeWordWrap].height;

CGFloat descriptionHeight = [event.descr sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(280, 100000) lineBreakMode:UILineBreakModeWordWrap].height;
self.descr.frame = CGRectMake(19, positionY, 280, descriptionHeight);
self.descr.text = event.descr;
self.descr.numberOfLines = 0; 

positionY =  self.descr.frame.origin.y + self.descr.frame.size.height + 40;

buyButton.frame = CGRectMake(19, positionY, 72, 37);

scrollView.contentInset = UIEdgeInsetsMake(contentInset, 0, 0, 0);
[scrollView setContentSize:CGSizeMake(320, positionY+80)];

UIScrollView has flexible height autoresizing mask set in IB. UIScrollView在IB中设置了灵活的高度自动调整大小蒙版。

Here is how it looks: 外观如下:

在此处输入图片说明

Can anyone tell me what am I doing wrong? 谁能告诉我我在做什么错?

UPDATE: 更新:

If I remove autoresizing mask for my UIScrollView - everything works okay 如果我删除UIScrollView的自动调整大小蒙版-一切正常

如果您的问题通过更改滚动视图上的自动调整大小掩码而得以解决,请确保检查按钮和标签上的自动调整大小掩码以确保它们均一致。

使用Count of UISCROLLVIEW子视图并将X轴作为

  CGRECTMAKE((count-count)*100)+x,y,width,height;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM