Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the height of a button with Swift?

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?

like image 332
Cuno Avatar asked May 04 '15 09:05

Cuno


People also ask

How do I change the size of a button in Xcode?

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.

How do I change TextField height in Swift?

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() .

How do I change the button style in Xcode?

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.


1 Answers

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.

like image 196
pteofil Avatar answered Sep 22 '22 16:09

pteofil