How can I change the height of a button using Swift?
Depending on the height of the screen, I would like to adjust the height of the button in the view. What's the easiest way to do it in Swift?
I tried it this way and also with CGRectMake()
, but nothing changed:
self.myButton.frame.size.height = self.myButton.frame.size.height*scrOpt
How can I "update" a frame?
source to share
The reason you don't see the changes might be because you are using AutoLayout and the button has some constraints applied to it and you need to change the height constraint to accomplish what you want.
Edited . Changing frame properties directly seems possible in Swift, but it is not possible in Objective C.
source to share
If you are using auto layout you need to update its height limit, otherwise update its frame
NSLog(@"%@",NSStringFromCGRect(self.myButton.frame));
NSLog(@"%f",scrOpt);
self.myButton.frame = CGRectMake(self.myButton.frame.origin.x, self.myButton.frame.origin.y, self.myButton.frame.size.width, self.myButton.frame.size.height*scrOpt)
NSLog(@"%@",NSStringFromCGRect(self.myButton.frame));
Edit this check and see what Print is NSLog
source to share