Not able to change the frame of UIButton Programma

2019-08-28 07:45发布

问题:

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