<small id='t8Mxb'></small><noframes id='t8Mxb'>

    <i id='t8Mxb'><tr id='t8Mxb'><dt id='t8Mxb'><q id='t8Mxb'><span id='t8Mxb'><b id='t8Mxb'><form id='t8Mxb'><ins id='t8Mxb'></ins><ul id='t8Mxb'></ul><sub id='t8Mxb'></sub></form><legend id='t8Mxb'></legend><bdo id='t8Mxb'><pre id='t8Mxb'><center id='t8Mxb'></center></pre></bdo></b><th id='t8Mxb'></th></span></q></dt></tr></i><div id='t8Mxb'><tfoot id='t8Mxb'></tfoot><dl id='t8Mxb'><fieldset id='t8Mxb'></fieldset></dl></div>

  1. <tfoot id='t8Mxb'></tfoot>
      • <bdo id='t8Mxb'></bdo><ul id='t8Mxb'></ul>
      <legend id='t8Mxb'><style id='t8Mxb'><dir id='t8Mxb'><q id='t8Mxb'></q></dir></style></legend>

      UIButton 在所有设备上的形状都不正确

      UIButtons are not correctly shaped on all devices(UIButton 在所有设备上的形状都不正确)
    1. <small id='4HZ7A'></small><noframes id='4HZ7A'>

      <legend id='4HZ7A'><style id='4HZ7A'><dir id='4HZ7A'><q id='4HZ7A'></q></dir></style></legend>

    2. <i id='4HZ7A'><tr id='4HZ7A'><dt id='4HZ7A'><q id='4HZ7A'><span id='4HZ7A'><b id='4HZ7A'><form id='4HZ7A'><ins id='4HZ7A'></ins><ul id='4HZ7A'></ul><sub id='4HZ7A'></sub></form><legend id='4HZ7A'></legend><bdo id='4HZ7A'><pre id='4HZ7A'><center id='4HZ7A'></center></pre></bdo></b><th id='4HZ7A'></th></span></q></dt></tr></i><div id='4HZ7A'><tfoot id='4HZ7A'></tfoot><dl id='4HZ7A'><fieldset id='4HZ7A'></fieldset></dl></div>
        <bdo id='4HZ7A'></bdo><ul id='4HZ7A'></ul>

            <tfoot id='4HZ7A'></tfoot>
                  <tbody id='4HZ7A'></tbody>

                本文介绍了UIButton 在所有设备上的形状都不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个带有四个方形按钮的 UIView 控制器,我用边框将它们设置为圆形.它在 iPhone 8 和 iPhone X 上完美运行,但在 iPhone SE 和 iPhone 8 Plus 中,UIButtons 不再是圆形的.我已将 UIButtons 设置为方形,并通过 Auto-Layout 保持该比例,但它似乎不起作用.

                I've an UIView Controller with four square buttons and I've set them round with a border. It works perfectly on iPhone 8 and iPhone X but in iPhone SE and iPhone 8 Plus the UIButtons are not round anymore. I've set the UIButtons to be square and to keep that ratio with Auto-Layout but it doesn't appear to work.

                在我的 ViewController.Swift 中,我已经链接了四个 UIButton,然后我应用了如下相同的代码:

                In my ViewController.Swift, I've linked the four UIButtons and then I've applied the same code as below :

                @IBOutlet weak var topLeftButtonImage: UIButton!
                
                
                // Edit it to round
                topLeftButtonImage.layer.cornerRadius = topLeftButtonImage.frame.size.width/2
                topLeftButtonImage.clipsToBounds = true
                
                // Add border
                topLeftButtonImage.layer.borderColor = UIColor.white.cgColor // Button border color
                topLeftButtonImage.layer.borderWidth = 4 // Button border width
                

                您可以在此处查看 iPhone SE 和 iPhone 8 Plus 上的行为.iPhone 8 和 iPhone X 都可以.

                Here you can see the behaviour on iPhone SE and iPhone 8 Plus. iPhone 8 and iPhone X are fine.

                自动布局约束:

                推荐答案

                在viewcontroller的viewDidLayoutSubviews方法中设置按钮cornerRadius

                set button cornerRadius in viewDidLayoutSubviews method of viewcontroller

                 override func viewWillLayoutSubviews() {
                    super.viewWillLayoutSubviews()
                    // Edit it to round
                    topLeftButtonImage.layer.cornerRadius = topLeftButtonImage.bounds.size.height / 2
                    topLeftButtonImage.clipsToBounds = true
                
                    // Add border
                    topLeftButtonImage.layer.borderColor = UIColor.white.cgColor // Button border color
                    topLeftButtonImage.layer.borderWidth = 4 // Button border width
                }
                

                这篇关于UIButton 在所有设备上的形状都不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Using Tint color on UIImageView(在 UIImageView 上使用 Tint 颜色)
                UIButton with both image and text possible?(可以同时具有图像和文本的 UIButton 吗?)
                Get button pressed id on Swift via sender(通过发件人在 Swift 上获取按钮按下的 id)
                How to detect one button in tableview cell(如何检测表格视图单元格中的一个按钮)
                Round Top Corners of a UIButton in Swift(Swift 中 UIButton 的圆顶角)
                Adding a closure as target to a UIButton(将闭包作为目标添加到 UIButton)

                    <i id='veeGx'><tr id='veeGx'><dt id='veeGx'><q id='veeGx'><span id='veeGx'><b id='veeGx'><form id='veeGx'><ins id='veeGx'></ins><ul id='veeGx'></ul><sub id='veeGx'></sub></form><legend id='veeGx'></legend><bdo id='veeGx'><pre id='veeGx'><center id='veeGx'></center></pre></bdo></b><th id='veeGx'></th></span></q></dt></tr></i><div id='veeGx'><tfoot id='veeGx'></tfoot><dl id='veeGx'><fieldset id='veeGx'></fieldset></dl></div>

                    <small id='veeGx'></small><noframes id='veeGx'>

                    1. <legend id='veeGx'><style id='veeGx'><dir id='veeGx'><q id='veeGx'></q></dir></style></legend>
                    2. <tfoot id='veeGx'></tfoot>

                        <bdo id='veeGx'></bdo><ul id='veeGx'></ul>
                          <tbody id='veeGx'></tbody>