【问题标题】:Not able to change the frame of UIButton Programmatically.?无法以编程方式更改 UIButton 的框架。?
【发布时间】:2014-12-18 07:45:22
【问题描述】:

我正在尝试在我的视图中添加更多文本字段,正在添加文本字段但按钮未更改框架。它消失在我添加的 uitextfield 中。请让我知道我哪里出错了。谢谢我在这里分享代码sn-p。

-(IBAction)addMore:(id)sender {
UITextField *moreText = [[UITextField alloc] initWithFrame:CGRectMake(20, textfieldy, 280, 44)];
CGRect buttonFrame = self.addmore.frame;
buttonFrame.origin.y += 10;
self.addmore.frame = buttonFrame;
textfieldy = textfieldy + 52;
addMorey = addMorey + 59;
addChecky = addChecky + 63;
[self.scrollView addSubview:moreText];
scrollView.contentSize = CGSizeMake(self.view.window.frame.size.width, 700);

[self.view setNeedsDisplay];

【问题讨论】:

    标签: objective-c uiscrollview uibutton uikit


    【解决方案1】:

    嗯,你真的应该使用自动布局。

    对于您当前的代码,缺少大量信息。看起来您只是在 y 原点位置添加了一个小偏移量,但没有考虑文本字段的高度。

    【讨论】:

    • 能否请您详细说明一下代码。这会很有帮助。我应该关闭 AutoLayout 吗?
    【解决方案2】:

    用它来设置框架...希望对您有所帮助..

    [self.addmore setFrame:CGRectMake([self.addmore.frame.origin.x, self.addmore.frame.origin.y+10, self.addmore.frame.size.width, self.addmore.frame.size.height)];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      相关资源
      最近更新 更多