以编程方式更改条形按钮背景图像的大小?

时间:2017-05-03 15:52:52

标签: ios swift image uibarbuttonitem

在我的导航栏中,我放了一个条形按钮,我为背景设置了一个图像。但是图像的大小远远大于按钮的大小。所以我试着解决这个问题,如下:

  override func viewDidAppear(_ animated: Bool) {
        let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 5, height: 5 ))
        imageView.contentMode = .center

        let image = UIImage(named: "Info")
        imageView.image = image

        info_btn.image = image
    }
然而,图片仍然延伸。知道怎么解决这个问题?

1 个答案:

答案 0 :(得分:0)

尝试<!DOCTYPE html> <html> <head> <title>Inzend Opgave H5</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <!-- style sheets --> <link href="style.css" rel="stylesheet" type="text/css" > </head> <body> <div id="wrapper"> <section class="container"> <form id="personInfo" name="myForm"> <table> <tbody id="table"> <tr> <td>nr.</td> <td>First Name</td> <td>Last Name</td> <td>Age</td> <td>Country</td> </tr> </tbody> </table> <input type="text" name="firstName" placeholder="firstName"> <input type="text" name="lastName" placeholder="lastName"> <input type="text" name="Age" placeholder="Age"> <select name="Country"> <option value="choose a country">Kies een land</option> <option value="Nederland">NL</option> <option value="Belgie">BE</option> <option value="Duitsland">DE</option> </select> <input type="button" name="button" id="btn" class="btn" value="Add the input fields to the table"> <p>To remove a table number fill in the input field with the <br> number of the table and click remove table row</p> <input type="button" name="button" id="removeRowBtn" class="btn" value="remove table row" style="width: 75%;"> <input type="text" name="TableNr" id="tableNr" placeholder="table nr."> </form> </section> </div> <!-- java-scripts --> <script type="text/javascript" src="script.js"></script> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script> <script type="text/javascript"> var cw = $('.container').width(); $('.container').css({ 'height': cw + 'px' }); </script> </body> </html>