• Keine Ergebnisse gefunden

Programmierung in iOS mit Swift Studiengang MI

N/A
N/A
Protected

Academic year: 2021

Aktie "Programmierung in iOS mit Swift Studiengang MI"

Copied!
25
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

1

FB Automatisierung und Informatik: iOS 1

Programmierung in iOS mit Swift

Studiengang MI

Dipl.-Inf., Dipl.-Ing. (FH) Michael Wilhelm

Hochschule Harz

FB Automatisierung und Informatik

mwilhelm@hs-harz.de

http://mwilhelm.hs-harz.de

Raum 2.202

Tel. 03943 / 659 338

FB Automatisierung und Informatik: iOS 2

Gliederung

Überblick:

Einleitung, Geschichte, xcode

Sprache Playground

Grafische Oberfläche

Projekt erstellen

UI erstellen

UI-Elemente

UI-Variablen

Action-Methoden (onClick-Events)

Layout-Typen

Core-Daten

Sensoren

(2)

FB Automatisierung und Informatik: iOS 3

Projekt erstellen

Starten von xcode

Neues Projekt

Master-Detail Application (MVC)

Paged Bases Application: Editor

Single View Application

Tabbed Application (Register)

Game

FB Automatisierung und Informatik: iOS 4

Projekt erstellen: Single View Application

(3)

3

FB Automatisierung und Informatik: iOS 5

Projekt erstellen: Projektdaten

FB Automatisierung und Informatik: iOS 6

Projekt erstellen: Speicherort

(4)

FB Automatisierung und Informatik: iOS 7

AppDelegate.swift

Startpunkt der App

ViewController.swift

Beinhaltet den Swift-Code eines UI-Views

Main.storyboard

Verwaltet den View oder die Views, „Controller“

Hier kann man die UI-Elemente Einfügen und Bearbeiten

Assets.xcassets

Verwaltet die Logos, Symbole

LaunchScreen.storyboard

Startfenster, Startlogos

Localisation, mehrere Sprachen

Info.pList

Property List Files, auch als Speicherung eigener Daten

Projektdateien

FB Automatisierung und Informatik: iOS 8

Projekt in xcode: IDE

(5)

5

FB Automatisierung und Informatik: iOS 9

Projekt in xcode: IDE

FB Automatisierung und Informatik: iOS 10

Projekt in xcode: IDE

(6)

FB Automatisierung und Informatik: iOS 11

UI-Oberfläche in xcode: UI-View (noch leer)

FB Automatisierung und Informatik: iOS 12

UI-Elemente in xcode

Label

Anzeige von Texten, readonly

Button

onClick-Event

Segemented Control

Mehrere Schalter in einem „JPanel“ (RadioButton)

Text

Texteditor, zeilenweise

Slider

Auswahl aus einem Bereich

Switch

Schalter, Anzeige eines Zustandes (An,Aus)

Activity Indicator

„Ich habe zu tun“

Progress View

Progressbar, Fortschrittsbalken, 0,0 bis 1,0

(7)

7

FB Automatisierung und Informatik: iOS 13

UI-Elemente in xcode

Text View

Texteditor, mehrere Zeilen

Scroll View

Erlaubt das UI-Element zu scrollen

Date Picker

Datum auswählen

Picker View

Jlist aus Java, eine Auswahl aus einer Liste

Benutzt einen Delegate, Konstruktor

Stepper

Schalter + und –

Table View Controller, JTable

Tab Bar Controller

SplitView, JPlitPane

ImageView WebView

FB Automatisierung und Informatik: iOS 14

UI-Elemente in xcode

(8)

FB Automatisierung und Informatik: iOS 15

UI-Elemente in xcode

FB Automatisierung und Informatik: iOS 16

UI-Elemente in den UI-View eintragen

Anzeige UI-Liste

Anzeige UI-View

Drag & Drop

(9)

9

FB Automatisierung und Informatik: iOS 17

UI-Elemente in den UI-View eintragen

UI-Elemente mittels Drag & Drop einfügen

Hier noch ohne Layout

FB Automatisierung und Informatik: iOS 18

Zielgerät

(10)

FB Automatisierung und Informatik: iOS 19

UI-Elemente ändern: Show Attributes Inspector

FB Automatisierung und Informatik: iOS 20

Attribute in UI-Elemente ändern: Name später!

(11)

11

FB Automatisierung und Informatik: iOS 21

Ändern der Größe / Positionen der UI-Elemente

UI-Elemente mittels Maus verschieben

UI-Elemente mittels Maus verkleinern, vergrößern

FB Automatisierung und Informatik: iOS 22

Referenz eines UI-Element in den Quellcode eintragen

View und Editor müssen sichtbar sein

CTRL-Taste drücke

Linke Maustaste drücken und zum Editor verschieben

Oben, nach class { „einfügen“

(12)

FB Automatisierung und Informatik: iOS 23

Referenz eines UI-Element in den Quellcode eintragen

FB Automatisierung und Informatik: iOS 24

Eintragen der Details des Quellcodes

(13)

13

FB Automatisierung und Informatik: iOS 25

ViewController.swift: class ViewController: UIViewController { // Attribute

var nr:Int32=0

@IBOutlet var bnAction: UITextField!

@IBOutlet var tInput: UITextField!

@IBOutlet var lblOutput: UILabel!

override func viewDidLoad() { }

override func didReceiveMemoryWarning() { }

@IBAction func bnActionClick(sender: AnyObject) { nr++

let input:String=tInput.text!

self.lblOutput.text=input+" "+String(nr) }

}

FB Automatisierung und Informatik: iOS 26

(14)

FB Automatisierung und Informatik: iOS 27

FB Automatisierung und Informatik: iOS 28

1. UI-Aufgabe

Taschenrechner

add

UI-Elemente

Label 1. Zahl

TextField 1. Zahl, uiAttribut

Label 2. Zahl

TextField 2. Zahl, uiAttribut

Button

Label Ergebnis

TextField Ergebnis, uiAttribut

Methoden

bnActionClick

(15)

15

FB Automatisierung und Informatik: iOS 29

1. UI-Aufgabe: Taschenrechner

FB Automatisierung und Informatik: iOS 30

(16)

FB Automatisierung und Informatik: iOS 31

1. UI-Aufgabe

UI-Elemente in den View eintragen

Button-Event eintragen

UI-Elemente als Referenz eintragen

FB Automatisierung und Informatik: iOS 32

1. UI-Aufgabe: Ablauf

Ausgabe eines Textes in der Event-Methode

tOutputCStrong.text!="Hallo"

Auswerten der Eingangsdaten

let sA:String = tInputAStrong.text!

Ausgabe

tOutputCStrong.text!=String(c)

(17)

17

FB Automatisierung und Informatik: iOS 33

1. UI-Aufgabe: Erweiterung mit ein SegmentedControl

FB Automatisierung und Informatik: iOS 34

UI-Element UILabel

Attribute

text

font, size etc.

Methoden

keine

(18)

FB Automatisierung und Informatik: iOS 35

UI-Element UITextField

Attribute

text

font, size etc.

Methoden

ValueChanged

Eintragen als Referenz (strong)

FB Automatisierung und Informatik: iOS 36

UI-Element UIButton

Attribute

text

font, size etc.

Methoden

Touch Up Inside Eintragen als Referenz (strong)

(19)

19

FB Automatisierung und Informatik: iOS 37

UI-Element UISegmentedControl (RadioButtons)

Attribute

Anzahl Buttons

text

font, size etc.

selectedSegmentIndex

Methoden

ChangeValue

FB Automatisierung und Informatik: iOS 38

UI-Element UISwitch

Attribute

on

if uiSwitch.on {

}

font, size etc.

Methoden

ValueChanged

(20)

FB Automatisierung und Informatik: iOS 39

FB Automatisierung und Informatik: iOS 40

UI-Element UISlider

Attribute

font, size etc.

minimum

maximum

value

Methoden

Value Changed

(21)

21

FB Automatisierung und Informatik: iOS 41

FB Automatisierung und Informatik: iOS 42

UI-Element UIStepper

Attribute

font, size etc.

minimum

maximum

value

Methoden

ValueChanged

(22)

FB Automatisierung und Informatik: iOS 43

FB Automatisierung und Informatik: iOS 44

UI-Element UIProgressView

Attribute

font, size etc.

minimum immer 0,0

maximum immer 1,0

value

Methoden

ValueChanged

(23)

23

FB Automatisierung und Informatik: iOS 45

FB Automatisierung und Informatik: iOS 46

UI-Element UIPickerView, ca. eine JList

Attribute

font, size etc.

delegate

Methoden

ValueChanged

(24)

FB Automatisierung und Informatik: iOS 47

FB Automatisierung und Informatik: iOS 48

class ViewController: UIViewController, UIPickerViewDelegate{

let staedte = ["Brüssel", "Mailand", "Moskau", "Rom"]

@IBOutlet var uiPickerView: UIPickerView!

funcnumberOfComponentsInPickerView(pickerView:UIPickerView)-> Int{

return 1 }

funcpickerView(pickerView:UIPickerView,

numberOfRowsInComponent component:Int) -> Int{

return staedte.count }

funcpickerView(pickerView:UIPickerView, titleForRow row:Int, forComponent component:Int) -> String?{

return staedte[row]

}

(25)

25

FB Automatisierung und Informatik: iOS 49

class ViewController: UIViewController, UIPickerViewDelegate{

funcpickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

labelErgebnis.text = staedte[row]

}

override func viewDidLoad() { super.viewDidLoad()

// Do any additional setup after loading the view, typically from a nib.

self.uiPickerView.delegate=self }

Referenzen

ÄHNLICHE DOKUMENTE

Weniger wichtig Welche User Stories sind so ähnlich Weniger wichtig Wurde eine User Stories schon bewertet Weniger wichtig Ist der Benutzer eingelogged Sehr wichtig.. Content

Wie gerecht die Justiz ist, darüber wird ab Dienstag dieser Woche wieder disku- tiert werden, garantiert. Und ebenso si- cher wird das Wort vom ,,Fehlurteil" zu

In addition to the special shapes in the first two categories, PenPoint allows any capital letter to be used as a gesture. The normal usage is to use the first letter of

Abbildung 3: Klassische Runge-Kutta Verfahren mit Schrittweite

Rule No.5 (Skewed cable lengths, supplement) - If the length of one of the cables connected to the affected lumped load in Rule No.4 must be increased because of that

Extension and interoperability of modelling languages towards a common denominator Fig. 2: Towards a common denominator in interdisciplinary UI-related modelling We integrate

WPARAM für WORD-Parameter (Win3x: 16 Bit, Win32: 32 Bit) WCHAR für „wide“ CHAR (Unicode, 16 Bit - ab WinNT).. TCHAR für „text“ CHAR (16 Bit für Unicode, 8

Der Frühling be­.. ginnt am