0

I want the bottom border height to be much taller than the rest of the borders to make the image look like a polaroid picture. Right now my code a has a standard border length for all 4 sides. I do not want the image to be cropped I just want the bottom border at a greater height. Below is my code. And here is a pitcure of the code results. Pice

import UIKit

class x1ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {

@IBOutlet weak var imageDisplay: UIImageView!
     var screenView: UIImageView!



@IBAction func camera(_ sender: AnyObject) {
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){
        let imagePicker = UIImagePickerController()
        imagePicker.delegate = self




        imageDisplay.layer.borderColor = UIColor(red: 0, green: 1.0, blue: 0, alpha: 1).cgColor
        imageDisplay.layer.cornerRadius = 1
        imageDisplay.contentMode = .scaleAspectFit
        imageDisplay.layer.borderWidth = 1


        imagePicker.sourceType = UIImagePickerControllerSourceType.camera;
        imagePicker.allowsEditing = false
        self.present(imagePicker, animated: true, completion: nil)}}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject: AnyObject]!){
    imageDisplay.image = image
    self.dismiss(animated: true, completion: nil);
    screenView = UIImageView()

    screenView.frame = CGRect(x:0, y: 0, width: self.view.frame.width, height: self.view.frame.height)




    let text = "#HAPPY"
    let label = UILabel(frame: CGRect(x: 125, y: 700, width: self.view.frame.width, height: 300))
    label.font = UIFont(name: label.font.fontName, size: 122)

    label.textColor = UIColor.blue
    label.alpha = 1.0
    label.text = text


    self.view.addSubview(screenView)
    self.view.addSubview(label)


    UIGraphicsBeginImageContext(self.imageDisplay.frame.size)
    self.view.drawHierarchy(in: self.view.frame, afterScreenUpdates: true)

}
@IBAction func save(_ sender: AnyObject) {

    let alert = UIAlertController(title: "Image Saved", message: "Image is in photo gallery", preferredStyle: .alert)
    let okay = UIAlertAction(title: "OK", style: .default, handler: nil)
    alert.addAction(okay)
    present(alert, animated: true, completion: nil)



    let photo = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    UIImageWriteToSavedPhotosAlbum(photo!, nil, nil, nil)

}


}
  • 1
    You need to add another `UIView` as a subview of your `UIImageView` and place it at the bottom using its `frame` property. – sdasdadas Dec 05 '16 at 16:41
  • This is good example available to add border to view. http://stackoverflow.com/a/30519213/2618600 – Nitya Dec 05 '16 at 16:48

1 Answers1

0

You can draw in a view using by overriding the rectdraw method and then add it above the image view. here the apple documentation: https://developer.apple.com/library/content/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/BezierPaths/BezierPaths.html

there is a tool that you can use to do the rectdraw code by dragging points with your mouse that can be useful. https://www.paintcodeapp.com/ you can try it for free.

Ponja
  • 663
  • 1
  • 8
  • 15