我希望底部边框高度比其他边框高得多,使图像看起来像宝丽来图片。现在我的代码a具有所有4个边的标准边框长度。我不希望裁剪图像我只想让底部边框更高。以下是我的代码。这里是代码结果的一个部分。
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)
}
}
答案 0 :(得分:0)
您可以通过覆盖rectdraw方法在视图中绘制,然后将其添加到图像视图上方。 这里有苹果文档:https://developer.apple.com/library/content/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/BezierPaths/BezierPaths.html
有一个工具,您可以使用鼠标拖动点来执行rectdraw代码,这可能很有用。 https://www.paintcodeapp.com/ 你可以免费试用。