title: How properly calculate cornerRadius depending on the button frame
body: <p>How to calculate <code>cornerRadius</code> property based on frame of the button to create rounded corners.</p>
  
  <p>I do not like to redefine each time corner <code>cornerRadius</code> for each button item.</p>
  
  <p>I create extension for the <code>UIButton</code>.</p>
  
  <pre><code>extension UIButton {
  
      func setRoundedCorners(){
          self.layer.cornerRadius = 10
          self.layer.borderWidth = 1
      }
  
  }
  </code></pre>
  
  <p>And i would like to know how too calculate dynamically <code>cornerRadius</code> each time i use this function.</p>
  
  <p>The main issue to find function that will calculate .cornerRadius for different button sizes. Example below will show small difference. </p>
  
  <p>Example:</p>
  
  <p>Corner radius is 10:</p>
  
  <p>:<a href="https://i.stack.imgur.com/2nEr7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2nEr7.png" alt="enter image description here"></a></p>
  
  <p>Corner radius is 15:</p>
  
  <p><a href="https://i.stack.imgur.com/Abetc.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Abetc.png" alt="enter image description here"></a></p>
  
  <p>Is it possible to find function that will calculate proper value that will give corner radius?</p>