Posts

Showing posts from October, 2015

How To Use UIScrollView In Swift

o to the ViewController.swift file and add the follwing properties var imageView: UIImageView! var scrollView: UIScrollView! override func viewDidLoad() {       super.viewDidLoad()   // 1     imageView = UIImageView(image: UIImage(named: "strandvagen.jpg"))      // 2   scrollView = UIScrollView(frame: view.bounds)   scrollView.backgroundColor = UIColor.blackColor()   // 3   scrollView.contentSize = imageView.bounds.size   // 4        scrollView.addSubview(imageView)   view.addSubview(scrollView) } class ViewController: UIViewController, UIScrollViewDelegate { @IBOutlet var scrollView: UIScrollView! var imageView: UIImageView! override func viewDidLoad() {   super.viewDidLoad()   // 1   let image = UIImage(named: "photo1.png")!   imageView = UIImageView(image: image)   imageView.frame = CGRect(origin: CGPoint(x: 0, y: 0), size:image.size)   scrollView.addSubview(imageView)   // 2   scrollView.contentSize = image.size   // 3   var doubleTapRecognizer = UITapGestureRe

Set Scrollview in Swift

override func viewWillLayoutSubviews () { super . viewWillLayoutSubviews (); self . scrollView . contentSize . height = 3000 ; // Or whatever you want it to be. }   override func viewWillLayoutSubviews () { super . viewWillLayoutSubviews (); self . scrollView . frame = self . view . bounds ; // Instead of using auto layout self . scrollView . contentSize . height = 3000 ; // Or whatever you want it to be. }

Draw rout using mapkit Swift

mapView ( mapView : rendererForOverlay ) rendererForOverlay ( overlay :)     func mapView ( mapView : MKMapView !, rendererForOverlay overlay :   MKOverlay !) -> MKOverlayRenderer ! { println ( "rendererForOverlay" ); if ( overlay is MKPolyline ) { var pr = MKPolylineRenderer ( overlay : overlay ); pr . strokeColor = UIColor . blueColor (). colorWithAlphaComponent ( 0.5 ); pr . lineWidth = 5 ; return pr ; } return nil }

How TO Work MKAnotation In Swift Ios

func mapView ( mapView : MKMapView !, annotationView view :     MKAnnotationView !, didChangeDragState newState :     MKAnnotationViewDragState , fromOldState oldState :     MKAnnotationViewDragState ) {   switch ( newState ) {   case . Starting : view . dragState = . Dragging case . Ending , . Canceling : view . dragState = . None default : break   } }

USe Of Simple TableView:In Swift Ios

var cell : UITableViewCell? var cell = tableView.dequeueReusableCellWithIdentifier("CELL") as? UITableViewCell if cell == nil {     cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "CELL") } //we know that cell is not empty now so we use ! to force unwrapping cell!.textLabel.text = "Baking Soda" cell!.detailTextLabel.text = "1/2 cup" cell!.textLabel.text = "Hello World" return cell Here's an example using a custom cell class: override func viewDidLoad() {     super.viewDidLoad()     self.tableView.registerClass(MyCell.self, forCellReuseIdentifier: "Cell") } override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {     let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath:indexPath) as MyCell     // no "if" - the cell is guaranteed to exist     // ... do stuff to the cell here ...     cell.tex

Custom UITableViewCell in Swift Ios

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!  {     var  cell:SimpleTableCell! = tableView.dequeueReusableCellWithIdentifier(simpleTableIdentifier) as? SimpleTableCell     if (cell == nil)     {         let nib:Array = NSBundle.mainBundle().loadNibNamed("SimpleTableCell", owner: self, options: nil)         cell = nib[0] as? SimpleTableCell     }     cell.nameLabel.text = tableData[indexPath.row]     cell.thumbnailImageView.image = UIImage(named:thumbnails[indexPath.row])     cell.prepTimeLabel.text = prepTime[indexPath.row];     return cell; }

How to Zoom UIScrollView In Swift

 ScrollViewController.swift var scrollView: UIScrollView! var imageView: UIImageView! override func viewDidLoad() {     super.viewDidLoad()             imageView = UIImageView(image: UIImage(named: "image.png"))             scrollView = UIScrollView(frame: view.bounds)     scrollView.backgroundColor = UIColor.blackColor()     scrollView.contentSize = imageView.bounds.size     scrollView.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight             scrollView.addSubview(imageView)     view.addSubview(scrollView) } scrollView.contentOffset = CGPoint(x: 1000, y: 450) ============================================================== class ScrollViewController: UIViewController, UIScrollViewDelegate { func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {     return imageView }     viewDidLoad(){     scrollView.delegate = self        scrollView.minimumZoomScale = 0.1     scrollView.maximumZoomScale = 4.0     scrollView.zoomSca

How To Use Go Viewing Previous/Next Pages in Swift Ios Iphone

PeekPagedScrollViewController.swif import UIKit class PeekPagedScrollViewController: UIViewController, UIScrollViewDelegate {   @IBOutlet var scrollView: UIScrollView!   @IBOutlet var pageControl: UIPageControl!   var pageImages: [UIImage] = []   var pageViews: [UIImageView?] = [] } override func viewDidLoad() {   super.viewDidLoad()   // Set up the image you want to scroll & zoom and add it to the scroll view   pageImages = [UIImage(named: "photo1.png")!,     UIImage(named: "photo2.png")!,     UIImage(named: "photo3.png")!,     UIImage(named: "photo4.png")!,     UIImage(named: "photo5.png")!] frame = CGRectInset(frame, 10.0, 0.0)   let pageCount = pageImages.count   // Set up the page control   pageControl.currentPage = 0   pageControl.numberOfPages = pageCount   // Set up the array to hold the views for each page   for _ in 0..<pageCount {     pageViews.append(nil)   }   // Set up the content si

How to Use pagination ScrollView in Swift

PagedScrollViewController.swift import UIKit class PagedScrollViewController: UIViewController, UIScrollViewDelegate {   @IBOutlet var scrollView: UIScrollView!   @IBOutlet var pageControl: UIPageControl! } var pageImages: [UIImage] = [] var pageViews: [UIImageView?] =[] override func viewDidLoad() {   super.viewDidLoad()   // 1   pageImages = [UIImage(named: "photo1.png")!,     UIImage(named: "photo2.png")!,     UIImage(named: "photo3.png")!,     UIImage(named: "photo4.png")!,     UIImage(named: "photo5.png")!]   let pageCount = pageImages.count   // 2   pageControl.currentPage = 0   pageControl.numberOfPages = pageCount   // 3   for _ in 0..<pageCount {     pageViews.append(nil)   }   // 4   let pagesScrollViewSize = scrollView.frame.size   scrollView.contentSize = CGSize(width: pagesScrollViewSize.width * CGFloat(pageImages.count),                                   height: pagesScrollViewSize.height)   // 5   loadVisiblePages() }

How To Use Custom ScrollVIew In Swift Ios

CustomScrollViewController.swift import UIKit class CustomScrollViewController: UIViewController, UIScrollViewDelegate {   @IBOutlet var scrollView: UIScrollView! } var containerView: UIView! override func viewDidLoad() {   super.viewDidLoad()   // Set up the container view to hold your custom view hierarchy   let containerSize = CGSize(width: 640.0, height: 640.0)   containerView = UIView(frame: CGRect(origin: CGPoint(x: 0, y: 0), size:containerSize))   scrollView.addSubview(containerView)   // Set up your custom view hierarchy   let redView = UIView(frame: CGRect(x: 0, y: 0, width: 640, height: 80))   redView.backgroundColor = UIColor.redColor();   containerView.addSubview(redView)   let blueView = UIView(frame: CGRect(x: 0, y: 560, width: 640, height: 80))   blueView.backgroundColor = UIColor.blueColor();   containerView.addSubview(blueView)   let greenView = UIView(frame: CGRect(x: 160, y: 160, width: 320, height: 320))   greenView.backgroundColor = UIColor.greenColor();   contain

How To Use UIScrollView In Swift

How To Use UIScrollView In Swift:- => ViewController.swift file and add the following properties:- var imageView: UIImageView! var scrollView: UIScrollView! override func viewDidLoad() {       super.viewDidLoad()   // 1     imageView = UIImageView(image: UIImage(named: "strandvagen.jpg"))      // 2   scrollView = UIScrollView(frame: view.bounds)   scrollView.backgroundColor = UIColor.blackColor()   // 3   scrollView.contentSize = imageView.bounds.size   // 4        scrollView.addSubview(imageView)   view.addSubview(scrollView) } class ViewController: UIViewController, UIScrollViewDelegate { @IBOutlet var scrollView: UIScrollView! var imageView: UIImageView! override func viewDidLoad() {   super.viewDidLoad()   // 1   let image = UIImage(named: "photo1.png")!   imageView = UIImageView(image: image)   imageView.frame = CGRect(origin: CGPoint(x: 0, y: 0), size:image.size)   scrollView.addSubview(imageView)   // 2   scrollView.conte

How To Use UICollectionView In Swift Ios

=> Here Given One of Example UIColletionView: //  AlbumViewController.swift //  UICollectionView+Swift import UIKit let reuseIdentifier = "Cell" class AlbumViewController: UICollectionViewController {     var Albums = Array<String>()        @IBAction func EditAlbumPressed(sender : AnyObject) {                if(self.navigationItem.rightBarButtonItem?.title == "Edit"){                    self.navigationItem.rightBarButtonItem?.title = "Done"                        for item in self.collectionView!.visibleCells() as [AlbumCell] {                                var indexpath : NSIndexPath = self.collectionView!.indexPathForCell(item as AlbumCell)!                 var cell : AlbumCell = self.collectionView!.cellForItemAtIndexPath(indexpath) as AlbumCell                                //Profile Picture                 //var img : UIImageView = cell.viewWithTag(100) as UIImageView                 //img.image = UIImage(named: "q.png") as UIImag

How Use UIImageView In UITableView Cell in Swift Ios/Iphone

=> Here way to use UIImageview with Class : class ViewController: UIViewController {     var bgImage: UIImageView?     override func viewDidLoad() {         super.viewDidLoad()         var image: UIImage = UIImage(named: "afternoon")!         bgImage = UIImageView(image: image)         bgImage!.frame = CGRectMake(0,0,100,200)         self.view.addSubview(bgImage!)     } } => Another way to use UIImageview: @IBOutlet weak var bgImage: UIImageView! var image : UIImage = UIImage(named:"afternoon")! bgImage = UIImageView(image: image) bgImage.frame = CGRect(x: 0, y: 0, width: 100, height: 200) view.addSubview(bgImage) => Another way to use UIImageview:  var imageViewObject :UIImageView  imageViewObject = UIImageView(frame:CGRectMake(0, 0, 600, 600))  imageViewObject.image = UIImage(named:"afternoon")  self.view.addSubview(imageViewObject)  self.view.sendSubviewToBack(imageViewObject) => here Resizing images: func resizeImage(image:UIImage, toTheSi

How To Work Use Of UITableView In Swift Ios/Iphone

import UIKit class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {        @IBOutlet var tableView: UITableView!        let textCellIdentifier = "TextCell"        let number= ["one", "two","three", "four", "five", "six", "seven", "eight", "nine", "ten"]     override func viewDidLoad() {         super.viewDidLoad()         tableView.delegate = self         tableView.dataSource = self     }        // MARK:  UITextFieldDelegate Methods     func numberOfSectionsInTableView(tableView: UITableView) -> Int {         return 1     }        func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         return number.count     }        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {         let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier,