title: Organize and adjust the UILabel position per devices - Swift 3
body: <p>I have SQLite database file and UILabel, and I set text for label from database on the number of characters after convert <code>String</code> to <code>Characters</code>, and I added extension its name (<code>length</code>), its job counts the number of characters.</p>
  
  <p><a href="https://i.stack.imgur.com/03API.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/03API.jpg" alt="enter image description here"></a></p>
  
  <p>My problem in this picture is : The UILabels are not organized in sizes and positions in per devices I want them to have their positions in the <strong>center of X-Axis</strong></p>
  
  <p><strong>Questions:</strong></p>
  
  <p><strong>1) How to set the label into center and set spaces right and left of screen for labels (per device) ??</strong></p>
  
  <p><strong>2) How to set width for labels if device is iPhone 7/6S/6 plus width = 50, if device is iPhone 7/6S/6 width = 45 and if device is iPhone SE/5S/5C/5 width = 38 ??</strong></p>
  
  <p><strong>3) Finally, how does the label become smaller by 10 if the number of characters is more than 8 ?</strong></p>
  
  <p><strong>This my code :</strong></p>
  
  <pre><code>func createTarget(id: Int) {
  
      listdata = dbHelpr.getDatabase(rowId: id)
  
      for data in listdata {
  
          let lengthOfChar : CGFloat = data.ans.length
          let yAxis : CGFloat = (self.view.frame.height) * 60%
          let width: CGFloat = view.frame.size.width - 40 // frame width
          var targetWidth: CGFloat = (width - (lengthOfChar - 1) * 5) / lengthOfChar
          let targetHeigt : CGFloat = 5
  
          if lengthOfChar &gt;= 8 {
              targetWidth = 40
          } else {
              targetWidth = 50
          }
  
          let totalWidth: CGFloat = (targetWidth * lengthOfChar) + ((lengthOfChar - 5) * 5)
  
          for (indexTar, tar) in data.ans.characters.enumerated() {
  
              let x : CGFloat = (width / 2) - (totalWidth / 2)
              let xx : CGFloat = (CGFloat(indexTar) * targetWidth) + (CGFloat(indexTar) * 5) + 20
              var xAxis : CGFloat = (x + xx)
              xAxis = width - xAxis
  
  
  
              let targetLabel = UILabel(frame: CGRect(x: xAxis, y: yAxis, width: targetWidth, height: targetHeigt))
              targetLabel.backgroundColor = .white
              targetLabel.layer.masksToBounds = true
              targetLabel.layer.cornerRadius = 5
              targetLabel.text = String(describing: tar)
              targetLabel.textAlignment = .center
              targetLabel.textColor = .white
              self.view.addSubview(targetLabel)
  
          }
  
      }
  
  }
  </code></pre>