Not able to change the frame of UIButton Programmatically.?

人盡茶涼 提交于 2019-12-25 05:33:35

问题


I am trying to add more textfields in my View, Textfield is getting added but the button is not changing the frame . And its gone inside the uitextfield which i have added . Please let me know where i am getting wrong . Thanks I am sharing the code snippet here itself.

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

回答1:


Well, you should really be using autolayout.

For your current code, there is a good amount of information missing. It looks like you're just adding a small offset to a y origin position, but not considering the height of the text field.




回答2:


Use this to set frame...I hope this will help you..

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


来源:https://stackoverflow.com/questions/27541532/not-able-to-change-the-frame-of-uibutton-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!