Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var toolIcon: UIButton!
var lastPoint = CGPoint.zero
var swiped = false
var red:CGFloat = 0.0
var green:CGFloat = 0.0
var blue:CGFloat = 0.0
var brushSize:CGFloat = 5.0
var opacityValue:CGFloat = 1.0
var tool:UIImageView!
var isDrawing = true
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
tool = UIImageView()
tool.frame = CGRect(x: self.view.bounds.size.width, y: self.view.bounds.height, width: 38, height: 38)
tool.image = #imageLiteral(resourceName: "brush")
self.view.addSubview(tool)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
swiped = false
if let touch = touches.first{
lastPoint = touch.location(in: self.view)
}
}
func drawLines(fromPoint:CGPoint,toPoint:CGPoint){
UIGraphicsBeginImageContext(self.view.frame.size)
imageView.image?.draw(in: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))
let context = UIGraphicsGetCurrentContext()
context?.move(to: CGPoint(x: fromPoint.x, y: fromPoint.y))
context?.addLine(to: CGPoint(x: toPoint.x, y: toPoint.y))
tool.center = toPoint
context?.setBlendMode(CGBlendMode.normal)
context?.setLineCap(CGLineCap.round)
context?.setLineWidth(brushSize)
context?.setStrokeColor(UIColor(red: red, green: green, blue: blue, alpha:opacityValue).cgColor)
context?.strokePath()
imageView.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
swiped = true
if let touch = touches.first{
let currentPoint = touch.location(in: self.view)
drawLines(fromPoint: lastPoint, toPoint: currentPoint)
lastPoint = currentPoint
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if !swiped {
drawLines(fromPoint: lastPoint, toPoint: lastPoint)
}
}
@IBAction func reset(_ sender: AnyObject) {
self.imageView.image=nil
}
@IBAction func erase(_ sender: AnyObject) {
if(isDrawing){
(red, green, blue) = (1,1,1)
tool.image = #imageLiteral(resourceName: "eraser_icon")
toolIcon.setImage(#imageLiteral(resourceName: "brush"), for: .normal)
}else{
(red, green, blue) = (0,0,0)
tool.image = #imageLiteral(resourceName: "brush")
toolIcon.setImage(#imageLiteral(resourceName: "eraser_icon"), for: .normal)
}
isDrawing = !isDrawing
}
@IBAction func save(_ sender: AnyObject) {
if let image = imageView.image{
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
}
@IBAction func setting(_ sender: AnyObject) {
}
@IBAction func colorChooser(_ sender: AnyObject) {
if sender.tag == 0{
(red, green, blue) = (0,0,0)
}else if sender.tag == 1{
(red, green, blue) = (1,0,0)
}else if sender.tag == 2{
(red, green, blue) = (0,1,0)
}else if sender.tag == 3{
(red, green, blue) = (0,0,1)
}else if sender.tag == 4{
(red, green, blue) = (1,1,0)
}else if sender.tag == 5{
(red, green, blue) = (0,1,1)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
let settingsVC = segue.destination as! SettingVC
settingsVC.delegate = self
settingsVC.red = red
settingsVC.green = green
settingsVC.blue = blue
settingsVC.brushSize = brushSize
settingsVC.opacityValue = opacityValue
}
}
extension ViewController:UINavigationControllerDelegate, UIImagePickerControllerDelegate, SettingsVCDelegate{
func settingsViewControllerDidFinish(_ settingsVC: SettingVC) {
self.red = settingsVC.red
self.green = settingsVC.green
self.blue = settingsVC.blue
self.brushSize = settingsVC.brushSize
self.opacityValue = settingsVC.opacityValue
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team