Posts

Showing posts from November, 2015

How To USe By Default Selecected Row And Checkmark UITableView In Swift

let indexPath = NSIndexPath ( forRow : 0 , inSection : 0 ); self . tableView . selectRowAtIndexPath ( indexPath , animated : false ,    scrollPosition : UITableViewScrollPosition . None ) self . tableView ( self . tableView , didSelectRowAtIndexPath : indexPath )   func tableView ( tableView : UITableView !, didSelectRowAtIndexPath  indexPath : NSIndexPath !) { NSLog ( "You selected cell number: \(indexPath.row)!" ) self . performSegueWithIdentifier ( "yourIdentifier" , sender : self )  }       override func tableView ( tableView : UITableView , didSelectRowAtIndexPath  indexPath : NSIndexPath ) { let indexPath = tableView . indexPathForSelectedRow () let currentCell = tableView . cellForRowAtIndexPath ( indexPath )     as UITableViewCell println ( currentCell . textLabel !. text )           override func viewDidLoad () { super . viewDidLoad () // … tableView . register

How To Hide Navigation Bar button in Swift

[[ self navigationController ] setNavigationBarHidden : YES animated : YES ];   [[ self navigationController ] setNavigationBarHidden : NO animated : YES ];   override func viewWillAppear ( animated : Bool ) { self . navigationController ?. navigationBarHidden = true }       override func viewWillAppear ( animated : Bool ) { self . navigationController ?. navigationBarHidden = false }     self . navigationItem . setHidesBackButton ( true , animated : false )

Work With NSLocal Country code in Swift

var pre = NSLocale . preferredLanguages ()[ 0 ]   var preferredLanguages : NSLocale ! let pre = preferredLanguages . displayNameForKey ( NSLocaleIdentifier ,   value : preferredLanguages )

Work With NSNotification Center In Swift Ios

  NSNotificationCenter . defaultCenter (). addObserver ( self , selector : "batteryLevelChanged:" , name : UIDeviceBatteryLevelDidChangeNotification , object : nil )     @objc func batteryLevelChanged ( notification : NSNotification ){ //do stuff }   ========================================= Send(Post) NSNotificationCenter . defaultCenter (). postNotificationName   ( "NotificationIdentifier" , object : nil )   Receive(Get) Notification   NSNotificationCenter . defaultCenter (). addObserver ( self , selector :     "methodOfReceivedNotification:" , name : "NotificationIdentifier" , object : nil )   Remove Notification NSNotificationCenter . defaultCenter (). removeObserver   ( self , name : "NotificationIdentifier" , object : nil ) NSNotificationCenter . defaultCenter (). removeObserver   ( self ) // Remove from all notifications being observed     Method h

How To Use Perfom Selector In Swift Ios/Iphone

NSTimer . scheduledTimerWithTimeInterval ( delay , target : self ,   selector : "onFlip" , userInfo : nil , repeats : false )     func performFlipOnDelay () { let delayInSeconds = 1.0 let delay = dispatch_time ( DISPATCH_TIME_NOW , Int64   ( delayInSeconds * Double ( NSEC_PER_SEC ))) dispatch_after ( delay , dispatch_get_main_queue ()) { onFlip (); } }

How To Chanage Navigation bar Color in Swift Ios

=> This code changes the NavigationBar color navigationController . navigationBar . barTintColor = UIColor . greenColor ()   => Navigation Bar Text:   navigationController . navigationBar . titleTextAttributes =     [ UITextAttributeTextColor : UIColor . orangeColor ()]      => Tab Bar Color:--   tabBarController . tabBar . tintColor = UIColor . yellowColor ()     => Change Bar Button Item:- UIBarButtonItem . appearance (). setTitleTextAttributes   ([ NSForegroundColorAttributeName : color , NSFontAttributeName : buttonFont ],   forState : UIControlState . Normal )

Pass Index One To Another Controller Swift Ios

var valueToPass : String ! func tableView ( tableView : UITableView !, didSelectRowAtIndexPath indexPath : NSIndexPath !) { println ( "You selected cell #\(indexPath.row)!" ) // Get Cell Label let indexPath = tableView . indexPathForSelectedRow (); let currentCell = tableView . cellForRowAtIndexPath ( indexPath !) as UITableViewCell !; valueToPass = currentCell . textLabel . text performSegueWithIdentifier ( "yourSegueIdentifer" , sender : self ) } override func prepareForSegue ( segue : UIStoryboardSegue , sender : AnyObject ?) { if ( segue . identifier == "yourSegueIdentifer" ) { // initialize new view controller and cast it as your view controller var viewController = segue . destinationViewController as AnotherViewController // your new view controller should have property that will store passed value viewController . passedValue = valueToPass

How To Know UIButton Pressed in Swift Ios

var button = UIButton ( frame : CGRect ( x : 0 , y : 0 , width : 150 , height : 60 )) button . backgroundColor = UIColor . blackColor () button . layer . cornerRadius = 3.0 button . setTitle ( "Tap Me" , forState : . Normal ) button . addTarget ( self , action : "buttonTapped" , forControlEvents : . TouchUpInside )   func buttonTapped () { println ( "Button tapped!" ) }

How to Use pagination ScrollView in Swift Ios/Iphone

agedScrollViewController.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 Multiple Cell In Swift UITableView IOs

unc tableView ( tableView : UITableView , cellForRowAtIndexPath indexPath : NSIndexPath ) -> UITableViewCell { cell . userInteractionEnabled = false if indexPath . section == 0 { let cell : FlightsDetailCell = tableView . dequeueReusableCellWithIdentifier ( "Cell" , forIndexPath : indexPath ) as FlightsDetailCell cell . graphView . enableBezierCurve = true cell . graphView . enableReferenceYAxisLines = true cell . graphView . enableYAxisLabel = true cell . graphView . colorYaxisLabel = UIColor . whiteColor () cell . graphView . delegate = UIApplication . sharedApplication (). delegate as   BEMSimpleLineGraphDelegate cell . graphView . dataSource = UIApplication . sharedApplication (). delegate as BEMSimpleLineGraphDataSource return cell } else if indexPath . section == 1 { let cell : FlightsDetailCell = tableView . dequeueReusableCellWithIdentifier ( "Cell" , forIndexP