Wednesday 29 October 2014

UITableView with checkbox in Swift Programing

import UIKit

class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate
{

    var tableview : UITableView!
   
    var ItemArray : NSMutableArray! = NSMutableArray()
    var addArray : NSMutableArray! = NSMutableArray()
    override func viewDidLoad()
    {
        super.viewDidLoad()
//self.view.backgroundColor=UIColor.redColor()
        // Do any additional setup after loading the view.
        
        
        let path = NSBundle.mainBundle().pathForResource("TableData", ofType: "plist")
        
        ItemArray = NSMutableArray(contentsOfFile: path!)

        println(ItemArray)
        
        tableview=UITableView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height), style: .Plain)
        tableview.delegate=self
        tableview.dataSource=self
        self.view.addSubview(tableview)
        
        
        
        
    }
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return ItemArray.count
    }
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 50
    }
    func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath)
    {
        
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "myCell")
        
    
//        tableview.separatorStyle=UITableViewCellSeparatorStyle.SingleLineEtched
//        cell.selectionStyle = UITableViewCellSelectionStyle.Blue;
//        cell.accessoryType = UITableViewCellAccessoryType.None
        var item : NSDictionary!
        
        item=ItemArray.objectAtIndex(indexPath.row) as NSDictionary
        println(item)
        var val=item.valueForKey("text") as String
        
        cell.textLabel?.text = val
        if (cell.accessoryView == nil)
        {
             // Only configure the Checkbox control once.
            
            var checkbox : Checkbox = Checkbox(frame: CGRectMake(0, 0, 25, 43))
            checkbox.checked=item.valueForKey("checked") as Bool
            checkbox.addTarget(self, action: "checkboxclicked:event:", forControlEvents: UIControlEvents.ValueChanged)
            cell.accessoryView=checkbox
            cell.accessoryView?.opaque=false
           
           

        }
        return cell
    }
    func checkboxclicked(sender:AnyObject, event:AnyObject)
    {
        println("DEMO")
        
        var touches :NSSet
        touches=event.allTouches()!
        var touch :UITouch
        touch=touches.anyObject() as UITouch
        var currentTouchPosition :CGPoint
        currentTouchPosition=touch.locationInView(tableview)
        var indexPath :NSIndexPath!
        indexPath=tableview.indexPathForRowAtPoint(currentTouchPosition)
        //        println(indexPath)
        
        if (indexPath != nil)
        {
            var addItem:NSDictionary!
            
            addItem=ItemArray[indexPath.row] as NSDictionary
            
            var addtext : String
            
            addtext=addItem.valueForKey("text") as String
            
            var index : NSInteger
            
            index=addArray.indexOfObject(addtext)
            
//            NSInteger index=[arrayOfStrings indexOfObject:yourString];
            if(NSNotFound == index)
            {
               println("NOT FOUND")
                
                addArray.addObject(addtext)
                
            }
            else
            {
                println("FOUND")
                addArray.removeObject(addtext)

            }
            println(indexPath.row)
            
        }
        else
        {
            
        }
    }
    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */


}

Here you can dowanload above code this link https://github.com/rnmano/CheckBoxSwift

Wednesday 15 October 2014

Slider Menu



    
    
    UISwipeGestureRecognizer *oneFingerSwipeLeft = [[UISwipeGestureRecognizer alloc]
                                                    initWithTarget:self
                                                    action:@selector(swipeLeft)] ;
    [oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
    [[self view] addGestureRecognizer:oneFingerSwipeLeft];
    
    UISwipeGestureRecognizer *oneFingerSwipeRight = [[UISwipeGestureRecognizer alloc]
                                                     initWithTarget:self
                                                     action:@selector(swipeRight)];
    [oneFingerSwipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
    [[self view] addGestureRecognizer:oneFingerSwipeRight];



-(void)swipeRight
{
    NSLog(@"RIGHT");
    if ([appdelegate.language isEqualToString:@"1"])
    {
    if(status==NO)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.4];
        //        self.navigationController.navigationBarHidden=NO;
        if([[UIScreen mainScreen]bounds].size.height==480)
        {
            frontview.frame = CGRectMake(280, 0, 320, 480);
            self.navigationController.navigationBarHidden=YES;
        }
        else
        {
            frontview.frame = CGRectMake(280, 0, 320, 568);
            self.navigationController.navigationBarHidden=YES;
        }
        
        status = YES;
    }
    [UIView setAnimationDuration:0.0];
    }
    else
    {
        if(status==YES)
        {
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.4];
            //        self.navigationController.navigationBarHidden=NO;
            if([[UIScreen mainScreen]bounds].size.height==480)
            {
                frontview.frame = CGRectMake(0, 0, 320, 480);
                self.navigationController.navigationBarHidden=YES;
            }
            else
            {
                frontview.frame = CGRectMake(0, 0, 320, 568);
                self.navigationController.navigationBarHidden=YES;
            }
            
            status = NO;
        }
        [UIView setAnimationDuration:0.0];
    }
}

-(void)swipeLeft
{
    NSLog(@"LEFT");
    if ([appdelegate.language isEqualToString:@"1"])
    {
        
            
    if(status == YES)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.4];
        if([[UIScreen mainScreen]bounds].size.height==480)
        {
            frontview.frame = CGRectMake(0, 0, 320, 480);
            self.navigationController.navigationBarHidden=YES;
        }
        else
        {
            frontview.frame = CGRectMake(0, 0, 320, 568);
            self.navigationController.navigationBarHidden=YES;
        }
        //        UIRefreshControl *refreshControl = [[UIRefreshControl alloc]  init];
        //        refreshControl.tintColor = [UIColor redColor];
        //        [bottomView addSubview:refreshControl];
        //        self.navigationController.navigationBarHidden=YES;
        status = NO;
    }
    [UIView setAnimationDuration:0.0];
    }
    else
    {
        if(status == NO)
        {
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.4];
            if([[UIScreen mainScreen]bounds].size.height==480)
            {
                frontview.frame = CGRectMake(-280, 0, 320, 480);
                self.navigationController.navigationBarHidden=YES;
            }
            else
            {
                frontview.frame = CGRectMake(-280, 0, 320, 568);
                self.navigationController.navigationBarHidden=YES;
            }
            //        UIRefreshControl *refreshControl = [[UIRefreshControl alloc]  init];
            //        refreshControl.tintColor = [UIColor redColor];
            //        [bottomView addSubview:refreshControl];
            //        self.navigationController.navigationBarHidden=YES;
            status = YES;
        }
        [UIView setAnimationDuration:0.0];
    }
}
- (void)ShowHide
{
    if ([appdelegate.language isEqualToString:@"1"])
    {
        if(status == NO)
        {
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.4];
            if([[UIScreen mainScreen]bounds].size.height==480)
            {
                frontview.frame = CGRectMake(280, 0, 320, 480);
                self.navigationController.navigationBarHidden=YES;
            }
            else
            {
                frontview.frame = CGRectMake(280, 0, 320, 568);
                self.navigationController.navigationBarHidden=YES;
            }
            //        UIRefreshControl *refreshControl = [[UIRefreshControl alloc]  init];
            //        refreshControl.tintColor = [UIColor redColor];
            //        [bottomView addSubview:refreshControl];
            //        self.navigationController.navigationBarHidden=YES;
            status = YES;
        }
        else
        {
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.4];
            //        self.navigationController.navigationBarHidden=NO;
            if([[UIScreen mainScreen]bounds].size.height==480)
            {
                frontview.frame = CGRectMake(0, 0, 320, 480);
                self.navigationController.navigationBarHidden=YES;
            }
            else
            {
                frontview.frame = CGRectMake(0, 0, 320, 568);
                self.navigationController.navigationBarHidden=YES;
            }
            status = NO;
        }
        [UIView setAnimationDuration:0.0];
    }
    else
    {
        if(status == NO)
        {
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.4];
            if([[UIScreen mainScreen]bounds].size.height==480)
            {
                frontview.frame = CGRectMake(-280, 0, 320, 480);
                self.navigationController.navigationBarHidden=YES;
            }
            else
            {
                frontview.frame = CGRectMake(-280, 0, 320, 568);
                self.navigationController.navigationBarHidden=YES;
            }
            //        UIRefreshControl *refreshControl = [[UIRefreshControl alloc]  init];
            //        refreshControl.tintColor = [UIColor redColor];
            //        [bottomView addSubview:refreshControl];
            //        self.navigationController.navigationBarHidden=YES;
            status = YES;
        }
        else
        {
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.4];
            //        self.navigationController.navigationBarHidden=NO;
            if([[UIScreen mainScreen]bounds].size.height==480)
            {
                frontview.frame = CGRectMake(0, 0, 320, 480);
                self.navigationController.navigationBarHidden=YES;
            }
            else
            {
                frontview.frame = CGRectMake(0, 0, 320, 568);
                self.navigationController.navigationBarHidden=YES;
            }
            status = NO;
        }
        [UIView setAnimationDuration:0.0];
   
    }

}

Monday 13 October 2014

Circle image View in iOS Objective c & Swift



Objective c


        self.img = [[UIImageView alloc] initWithFrame:CGRectMake(18, 8, 100, 100)];
        self.img.clipsToBounds = YES;
        self.img.layer.cornerRadius = self.img.frame.size.width / 2;
        self.img.clipsToBounds = YES;
        self.img.layer.borderWidth=1.0f;


Swift

        self.img = [[UIImageView allocinitWithFrame:CGRectMake(188100100)];
        self.img.clipsToBounds = YES;
        self.img.layer.cornerRadius = self.img.frame.size.width / 2;
        self.img.clipsToBounds = YES;
        self.img.layer.borderWidth=1.0f;

Monday 22 September 2014

iOS Swift

Requirements:
  1.Xcode6 or Later
  2.Mac Osx 10.10 Later

Development:

Variable Declaration in ios Swift

       Local Variable


             var engine : NSString = ""

      Global Variable

             var engine : NSString?

UIAlertController

   var alert = UIAlertController(title: "Alert", message:"welcome" as String , preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
        self.presentViewController(alert, animated: true, completion: nil)

Creating Method:

   func searchItunesFor(searchTerm: String)
    {
         Print(searchTerm) //This is print log or console
       }

Where

   searchItunesFor-Method Name
   searchTerm:     -receiver Parameter 
   String               -Type of Parameter

Method Calling

    searchItunesFor("JQ Software")

Array and Dictionary 

     var tableData: NSArray = []
  var rowData: NSDictionary= self.tableData[indexPath.row] as NSDictionary

Json Request

func searchItunesFor(searchTerm: String)
    {
        
        // The iTunes API wants multiple terms separated by + symbols, so replace spaces with + signs
        var itunesSearchTerm = searchTerm.stringByReplacingOccurrencesOfString(" ", withString: "+", options: NSStringCompareOptions.CaseInsensitiveSearch, range: nil)
        
        // Now escape anything else that isn't URL-friendly
        var escapedSearchTerm = itunesSearchTerm.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
        var urlPath = "https://itunes.apple.com/search?term=\(escapedSearchTerm)&media=software"
        var url: NSURL = NSURL(string: urlPath)
        var session = NSURLSession.sharedSession()
        var task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in
            println("Task completed")
            if(error) {
                // If there is an error in the web request, print it to the console
                println(error.localizedDescription)
            }
            var err: NSError?
            var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
            if(err?) {
                // If there is an error parsing JSON, print it to the console
                println("JSON Error \(err!.localizedDescription)")
            }
//             println(jsonResult)
            var results: NSArray = jsonResult["results"] as NSArray
            dispatch_async(dispatch_get_main_queue(), {
                self.tableData = results
                self.appsTableView.reloadData()
                })
            })
        task.resume()
    }


UITableView Delegate And DataSource


//Number of Row in tableView

  func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
    {
        return tableData.count
    }
    
// cellForRowAtIndexPath in tableView


    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell
{
        let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell")
        
        var rowData: NSDictionary = self.tableData[indexPath.row] as NSDictionary
        
        cell.text = rowData["trackName"] as String
        
        // Grab the artworkUrl60 key to get an image URL for the app's thumbnail
        var urlString: NSString = rowData["artworkUrl60"] as NSString
        var imgURL: NSURL = NSURL(string: urlString)
        
        // Download an NSData representation of the image at the URL
        var imgData: NSData = NSData(contentsOfURL: imgURL)
        cell.image = UIImage(data: imgData)
        
        // Get the formatted price string for display in the subtitle
        var formattedPrice: NSString = rowData["formattedPrice"] as NSString
        
        cell.detailTextLabel.text = formattedPrice
        
        return cell
    }

    
//  didSelectRowAtIndexPath in tableView

  func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath:
        
        NSIndexPath!)
     {
  tableView.deselectRowAtIndexPath(indexPath, animated: false)
  
            var rowData: NSDictionary = self.tableData[indexPath.row] as NSDictionary
 }
    
    func tableView(tableView: UITableView!, canEditRowAtIndexPath indexPath: NSIndexPath!) -> Bool
    {
        return true
    }
    


    func tableView(tableView: UITableView!, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!) {
        if (editingStyle == UITableViewCellEditingStyle.Delete) {
            // handle delete (by removing the data from your array and updating the tableview)
        }
    }
    
//  heightForRow in tableView

    func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat
    {
        return 70.0;
    }

navigationController

  ie Left Bar Button and Right Bar Button

 Left Bar Button

 navigationController.setNavigationBarHidden(false, animated:true)
        var myBackButton:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
        myBackButton.addTarget(self, action: "popToRoot:", forControlEvents: UIControlEvents.TouchUpInside)
        myBackButton.setTitle("Back", forState: UIControlState.Normal)
        myBackButton.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
        myBackButton.sizeToFit()
        var myCustomBackButtonItem:UIBarButtonItem = UIBarButtonItem(customView: myBackButton)
        self.navigationItem.leftBarButtonItem  = myCustomBackButtonItem
        

Right Bar Button

        var myRightButton:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
        myRightButton.addTarget(self, action: "numberTapped:", forControlEvents: UIControlEvents.TouchUpInside)
        myRightButton.setTitle("Alert", forState: UIControlState.Normal)
        myRightButton.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
        myRightButton.sizeToFit()
        var myCustomRightButtonItem:UIBarButtonItem = UIBarButtonItem(customView: myRightButton)
        self.navigationItem.rightBarButtonItem  = myCustomRightButtonItem

func popToRoot(sender:UIBarButtonItem)
    {
        self.navigationController.popToRootViewControllerAnimated(true)
//         self.dismissModalViewControllerAnimated(true)
    }


@IBAction func numberTapped(sender: AnyObject)
{
    var alert = UIAlertController(title: "Alert", message:"welcome" as String , preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
        self.presentViewController(alert, animated: true, completion: nil)
}


UIWebview Load URL


  @IBOutlet var appsWebView : UIWebView


  appsWebView.frame=CGRectMake(0, 150, self.view.bounds.width, self.view.bounds.height-150)

        let url = NSURL(string: "http://www.google.com")
        let request = NSURLRequest(URL: url)
        appsWebView.loadRequest(request)
               appsWebView.sizeToFit()
        appsWebView.setNeedsDisplay()
        appsWebView.setNeedsLayout()

One class to another class move




        let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
        
        let vc :ViewController1 = mainStoryboard.instantiateViewControllerWithIdentifier("SecondViewController") as ViewController1
   

navigationController


        self.navigationController.pushViewController(vc, animated: true)

presentViewController


       self.presentViewController(navigationController, animated: true, completion: nil)





Wednesday 19 February 2014

Phonegp Install command line tool Process


On the Mac, the command-line is available via the Terminal application. On the PC, it's available as Command Prompt underAccessories.
The more likely it is that you run the CLI from different machines, the more it makes sense to maintain a remote source code repository, whose assets you pull down to local working directories.
To install the phonegap command-line tool, follow these steps:
  1. Download and install Node.js. Following installation, you should be able to invoke node or npm on your command line.
  2. Install the phonegap utility. In Unix, prefixing the additional sudo command may be necessary to install development utilities in otherwise restricted directories:
    $ sudo npm install -g phonegap
    The installation log may produce errors for any uninstalled platform SDKs. Following installation, you should be able to run phonegap on the command line.

Create the App

Go to the directory where you maintain your source code, and run a command such as the following:
    $ phonegap create hello com.example.hello HelloWorld
The first argument specifies a hello directory to be generated for your project. Its www subdirectory houses your application's home page, along with various resources under cssjs, and img, which follow common web development file-naming conventions. The config.xml file contains important metadata needed to generate and distribute the application.
The other two arguments are optional: the com.example.hello argument provides your project with a reverse domain-style identifier, and the HelloWorld provides the application's display text. The -i and -n command-line options and their corresponding flags make these explicit:
    $ phonegap create hello -n HelloWorld -i com.example.hello
    $ phonegap create hello --name HelloWorld --id com.example.hello
Alterately, you can edit both of these optional values in the config.xml file later during development.

Build the App

All subsequent commands need to be run within the project's directory, or any subdirectories within its scope:
    $ cd hello
By default, the phonegap create script generates a skeletal web-based application whose home page is the project's www/index.html file, with its default logic referenced from www/js/index.js. Edit this application however you want, but initialize it as part of a deviceready event handler, which executes once device APIs become available.
The build command compiles an application for whichever platform you specify, identified by common stub arguments, generating platform-specific files within the project's platforms subdirectory. For example, the following targets iPhone and iPad devices:
    $ phonegap build ios
    [phonegap] detecting iOS SDK environment...
    [phonegap] using the local environment
    [phonegap] compiling iOS...
    [phonegap] successfully compiled iOS app
High-level information on the command's progress displays as feedback. If you need lower-level details, use the -V (verbose) option:
    $ phonegap -V build ios