[SWIFT] Make a margin to the left of the TextField

TextField has properties called leftView and rightView, so I will place a transparent View there to create a margin. If you generate a TextField with the following code,

textField.borderStyle = .line
self.view.addSubview(textField)
//Auto layout
textField.translatesAutoresizingMaskIntoConstraints = false
textField.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.8).isActive = true
textField.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
textField.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true

スクリーンショット 2020-10-08 13.49.20.png

The first letter is too close to the border on the left. So let's add the following code.

textField.leftViewMode = .always
textField.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: 30))

スクリーンショット 2020-10-08 13.52.26.png

I was able to add a margin! You can make a margin on the right side in the same way. You can also arrange buttons, so it seems that you can use it in various ways!

Recommended Posts

Make a margin to the left of the TextField
Set the time of LocalDateTime to a specific time
How to make a unique combination of data in the rails intermediate table
How to make a mod for Slay the Spire
[Ruby] I want to make a program that displays today's day of the week!
I want to make a specific model of ActiveRecord ReadOnly
[Ruby] How to retrieve the contents of a double hash
I tried to make a client of RESAS-API in Java
[jsoup] How to get the full amount of a document
I tried to make the sample application into a microservice according to the idea of the book "Microservice Architecture".
Try to make a simple callback
How to make a Java container
How to make a JDBC driver
A memorandum of the FizzBuzz problem
How to make a splash screen
How to make a Jenkins plugin
How to make a Maven project
Try to make a peepable iterator
How to make a Java array
Try to imitate the idea of a two-dimensional array with a one-dimensional array
A solution to the problem of blank spaces at the beginning of textarea
How to display 0 on the left side of the standard input value
I made a gem to post the text of org-mode to qiita
[Java] I tried to make a maze by the digging method ♪
A good way to make a recursive function that reverses the characters
How to identify the path that is easy to make a mistake
Try to make a CS 3D tile from the Geographical Survey tile
[chown] How to change the owner of a file or directory
Let's make a custom_cop that points out the shaking of the name
I made a tool to output the difference of CSV file
How to check for the contents of a java fixed-length string
Three Reasons to Frustrate Before the Release of a Web Service
I tried to make a parent class of a value object in Ruby
A memo that was soberly addicted to the request of multipart / form-data
How to make a Java calendar Summary
Make a note of Ruby keyword arguments
A memo when you want to clear the time part of the calendar
The secret to the success of IntelliJ IDEA
Make a daily build of the TOPPERS kernel with Gitlab and Docker
The story of forgetting to close a file in Java and failing
The road to creating a music game 2
Procedure to make the value of the property file visible in Spring Boot
How to determine the number of parallels
How to make a Discord bot (Java)
How to set an image in the drawable Left / Right of a button using an icon font (Iconics)
How to find out the Java version of a compiled class file
[Java] How to get to the front of a specific string using the String class
How to sort the List of SelectItem
Output of the book "Introduction to Java"
How to change the value of a variable at a breakpoint in intelliJ
I tried to make full use of the CPU core in Ruby
How to get the absolute path of a directory running in Java
The process of introducing Vuetify to Rails
Ability to display a list of products
Find the difference from a multiple of 10
The road to creating a music game 3
How to make the schema of the URL generated by Rails URL helper https
The road to creating a music game 1
I tried to make a sample program using the problem of database specialist in Domain Driven Design
Since the image of the lock screen of Windows 10 is beautiful, I wanted to make it a slide show of wallpaper
[Ruby on Rails] How to make the link destination part of the specified id