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

10 Şubat 2015 Salı

Swift Basics - Array and Dictionary


Simple Values

let -> make a constant
var -> make a variable 

In order to assign a value, we may not write type explicitly

Example:

    let constantValue = 20
        let constantValue2 : Int = 20

 Error:  Cannot assign to 'let' value 'constantValue'
constantValue = 30.5
 Error:  Cannot assign to 'let' value 'constantValue2’
        constantValue2 = 30

Change let to var
  var Value = 20
        var Value2 : Int = 20
      
 Error:  Type 'Int' does not conform to protocol 'FloatLiteralConvertible'
        Value = 30.5
  It’s OK
        Value2 = 30


Convert to “Int” type to “String” type

let stringValue = "The height of frame is "
        let height = 100
        let ​heightLabel​ = stringValue + String(height)
        
        
        println(​heightLabel​)

Convert to any type to String type basically.


  let height = 100
        let stringValue = "The height of frame is  \(height)"
        let ​heightLabel​ = stringValue
        
        
        println(​heightLabel​)


Change an item of array

        var arrayList = ["cat","dog","bird"]
        arrayList[1] = "penguen"
        
        for var i=0; i<arrayList.count; i++
        {println(arrayList[i])
        }

Add an item of array by using append method

        arrayList.append("bear")
 

Add an array of one or more compatible items
        arrayList += ["cow","butterfly"]

To insert an item into the array at a specified index:
        arrayList.insert("bee", atIndex: 4)

To remove an item from array
  arrayList.removeAtIndex(5)









24 Ocak 2015 Cumartesi

Basic AutoLayout Example in iOS - 1

Let's make a basic autolayout example.

Firstly add a blue view the upper left corner.

Add the constraints for the blue view

height = 100
width = 100


Update Frames for blue view






Seconly, add a purple view the center

Add the constraints for the purple view

height = 200
width = 200


In order to show a view on the center, we must add alignment constraints:
1. Horizontal center in Container
2. Vertical center in Container


Update Frames for purple view


Finally add a orange view the upper left corner.

Add the constraints for the orange view

height = 100
width = 100

Update Frames for orange view

Let's control storyboard preview for iPhone sizes.




Result for iPhone 6








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





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