Search code examples
iosxcodeuiimageviewuitextfieldswift5

Adding Text and Images in the same field in Swift


I wanted to make a kind of a notes app where users can add images inline with text, similar to how iOS' native Notes app does. Any advice on approaches I could take for this?

I'm new to iOS development and have been trying to teach myself a bunch of necessary skills and was curious as to how someone would go about doing this.

Thanks!


Solution

  • You can use UITextField to add images and text in one field, It can be done by using storyboard also and to do it programmatically is also convenient. Find the below code to add image programmatically in a text field :

    var imageView = UIImageView()
    var image = UIImage(named: "email.png")
    imageView.image = image
    emailField.leftView = imageView
    emailField.leftViewMode = UITextFieldViewMode.always
    emailField.leftViewMode = .always