Depending on the height of the screen, I would like to adjust the height of a button in a view. What is the easiest way to do this in Swift?
I tried it in this way and also with CGRectMake()
but nothing changed:
self.myButton.frame.size.height = self.myButton.frame.size.height*scrOpt
How can I "update" the frame?
You can customize width and height of button using storyboard in Xcode. Just select your button and open this window. After that just add the height constraints.
Step 1 : Click the Attribute Inspector, Select the Border Styles which is not the rounded one. Step 2 : Now go to Size Inspector and change the size of the TextField. Step 3 : Create an @IBOutlet for TextField and then add below code inside the viewWillAppear() or viewDidAppear() .
If you want to style all buttons in your app in a standard way, then you would style the appearance proxy for UIButton . You get one by calling the class method UIButton. appearance() , and then styling the returned value the way you want your buttons to look.
The reason why you see no changes may be because you're 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 to be possible in Swift but was not possible in Objective C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With