-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifyProfile.swift
149 lines (123 loc) · 5.13 KB
/
modifyProfile.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//
// modifyProfile.swift
// My Diabetic Manager
//
// Created by Anna Belardo on 02/02/17.
// Copyright © 2017 Vincenzo De Rosa. All rights reserved.
//
import UIKit
class modifyProfile: UIViewController , UIImagePickerControllerDelegate, UINavigationControllerDelegate{
@IBOutlet var newN : UITextField!
@IBOutlet var newS: UITextField!
@IBOutlet var newI : UITextField!
@IBOutlet var newE : UITextField!
@IBOutlet var newB : UITextField!
@IBOutlet var newP: UITextField!
@IBOutlet var newIm : UIImageView!
@IBOutlet var save : UIBarButtonItem!
@IBOutlet weak var pickedImaged: UIImageView!
var newName : String = ""
var newSurname : String = ""
var newICHO : String = ""
var newEmail : String = ""
var newBirthdate : String = ""
var newPassword : String = ""
var newImage : String = ""
override func viewDidLoad() {
super.viewDidLoad()
newN.text = newName
newS.text = newSurname
newI.text = newICHO
newE.text = newEmail
newB.text = newBirthdate
newP.text = newPassword
//immagine rotonda
newIm.layer.borderWidth = 1
newIm.layer.masksToBounds = false
newIm.layer.cornerRadius = newIm.frame.size.height/2
newIm.layer.cornerRadius = newIm.frame.size.width/2
newIm.clipsToBounds = true
newIm.layer.borderColor = hexStringToUIColor(hex: "034f84").cgColor
newIm.image = UIImage (named: newImage)
pickedImaged.image = UIImage ( named: "Simba")
/*
super.viewDidLoad()
picker.delegate = self
*/
// Do any additional setup after loading the view.
}
func hexStringToUIColor (hex:String) -> UIColor {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.characters.count) != 6) {
return UIColor.gray
}
var rgbValue:UInt32 = 0
Scanner(string: cString).scanHexInt32(&rgbValue)
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//scattare uan foto
@IBAction func camerabuttonaction (_ sender: UIButton){
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
;
imagePicker.allowsEditing = false
self.present(imagePicker, animated: true,
completion: nil)
}
}
// scegliere foto da libreria
@IBAction func photolibraryaction (_ sender: UIButton){
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary)
{
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
}
}
//Salvo i nuovi dati del profilo modificati
@IBAction func save(_ sender: UIBarButtonItem){
//roba per foto
let imageData = UIImageJPEGRepresentation(pickedImaged.image!, 0.6)
let compressJPEGImage = UIImage(data: imageData!)
UIImageWriteToSavedPhotosAlbum(compressJPEGImage!, nil, nil, nil)
saveNotice()
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo :[NSObject: AnyObject]!) {
pickedImaged.image = image
self.dismiss(animated: true, completion: nil);
}
func saveNotice () {
let alertController = UIAlertController(title: "Successfully Update!", message: "Your data was successfully update.", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alertController.addAction(defaultAction)
present (alertController, animated: true, completion: nil)
}
/*
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ProfileSummary"{
let destinationController = segue.destination as! ProfileSummary
destinationController.Name = newName
destinationController.Surname = newSurname
destinationController.ICHO = newICHO
destinationController.OminoImage =
}
}*/
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
}