swift etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
swift etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

19 Mayıs 2015 Salı

Create a new Xcode Project in Swift Language

1. Launch Xcode



You can access Xcode from /Developer/Applications. When Xcode is launched, you see the Welcome screen. In the right column, most recent projects which you open are listed.



If you want to use Xcode without the Welcome screen , deselect the "Show This Window When Xcode Launches" check box.






2. Create a new Xcode project 


There are two ways to create a new project

a. Select  a new Xcode project

b. Select File->New-> Project
  

3.  Select an application type



There are a few templates in the New Project window such as Master-Detail Application, Page Based application, game etc.  According to your need , you can choice one of them.



4. Enter a project name and select language and device type.


   In the this window, project options are listed. You can choose iPhone, iPad or universal as device type and Swift or Objective-C as language. 




5. Choose Project location in your computer 



3 Şubat 2015 Salı

Dynamic TableView Height using AutoLayout in Swift









iPhone has different sizes. In order to a tableview's height is suitable for any iPhone size, we can use autolayout.

An examle for Dynamic TableView Height using AutoLayout in mobile development

1. Add a tableview in view and implement UITableView Delegate and Data Source








class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
...




2. Define tableview width

For Tableview width = iPhone width , we should define "equals width"



3. Add top and bottom space constraints

For Statusbar space, we should define "20"  top space
For horizontal space and vertical bottom space,  we should define "0". Since we define bottom space  as  "0" , tableview height has dynamic height.


4.  Control the storyboard preview for different iPhone sizes




5. Add an outlet object for TableView



5. Register tableview class


Add register class method in viewDidLoad

self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")


6. Add tableview methods for testing

  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 100;
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
        
        cell.backgroundColor = UIColor.clearColor()
        cell.textLabel.text = "item \(indexPath.row)"
        
        
        
        return cell
    }
    
    func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
        println("Tablecell #\(indexPath.row)!")
    }


7. Result for iPhone 6




You can download from https://github.com/ozlemakalin/DynamicTableViewHeightSwift


   


15 Ocak 2015 Perşembe

Custom Button in Swift



Custom Buttons 

Create a swift file for custom button










Create a custom button class



class CustomButton: UIButton {
     required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.layer.borderColor = UIColor.yellowColor().CGColor
        self.layer.borderWidth = 5
        self.backgroundColor = UIColor.redColor()
        
}


}


Define custom button class in Storyboard






For custom button with imageview and label

Create view and add imageview and label in view
Add button on image view and label
Define constraints







 Result



You can download from https://github.com/ozlemakalin/custombuttonswift





2 Ocak 2015 Cuma

Custom tableviewcell iOS Development in Swift


Custom tableviewcell example is developed for Swift language.

An examle for Custom tableviewcell in mobile development

Create a new project




Choose swift language


Add a table view and TableView Delegate and DataSource protocols in ViewController