Showing posts with label begineers. Show all posts
Showing posts with label begineers. Show all posts

Saturday, February 6, 2021

Xcode 11.6 (Swift 5.2.4) - Hello World and how to set the background color programmatically

 code:

import SwiftUI


struct ContentView: View {

    let screenWidth = UIScreen.main.bounds.width

    var body: some View {

        ZStack {

            Color.yellow

            .edgesIgnoringSafeArea(.all)

            Text("Hello, World!")

            

            Text("Study Swift")

            .position(CGPoint(x: screenWidth/2, y: 400))

            

        }

    }

}


struct ContentView_Previews: PreviewProvider {

    static var previews: some View {

        ContentView()

    }

}

Result:


Reference:


How to set a background color for the viewController in swiftUI? (StackOverflow)

Tuesday, March 15, 2016

Xcode Tip: Screenshot for iOS/tvOS device/simulator

To capture the screen of an iPhone/iPad/Apple TV connected to a Mac or the screen of the iOS/tvOS simulator, try the following instructions:

iOS/tvOS Device

Method 1

Select Xcode -> Debug -> View Debugging -> Take Screenshot of (device name)


Method 2

Select Xcode -> Window -> Devices


Select your device -> Take Screenshot


A screenshot PNG file will be stored to the desktop.

iOS/tvOS Simulator

Select Simulator -> File -> Save Screen Shot




or hold these two keys: [Command] + [S]

A screenshot PNG file will also be stored to the desktop.

==================

iOS/tvOS Device without a Mac

If you want to make a screen capture of an iPhone/iPad without connecting to a Mac, hold the [Sleep/Wake (Power)] button and press and release the [Home] button.

An image of the device screen will be saved in Photos app.

Thursday, March 10, 2016

How to get the Bundle Identifier in Xcode

New iOS developers may be unfamiliar with the Bundle Identifier (Bundle ID). You need to know it while submitting apps to the App Store or utilizing some third party APIs, such as Facebook and Google APIs.

While creating a new Xcode project, you need to enter a product name and an organization identifier in the dialog shown below. And these two items are joined together to form the bundle ID, such as com.mycompany.UIButton.



To get the bundle ID of an existing project, select the top project item in the project navigator at the left. Then select TARGETS -> General. Then the bundle identifier is shown as below:



Here you may change the bundle ID to any form you like for a project already created.

Saturday, June 28, 2014

Hello World for non-programmers 新手程式設計師的第一段Swift程式

Update: January 10, 2016 - Add the print commands for Swift 2 and add a link to IBM Swift Sandbox.

Hello World - The first step in learning a new programming language. It usually displays a simple string on the terminal / console.

Execute the code below in IBM Swift Sandbox with the RUN button and try to modify the constants and variables in the code.
IBM Swift Sandbox中按RUN按鈕並嘗試改改程式中的常數及變數

//Swift 1:
//println("Hello World!")
//Swift 2:
print("Hello World!")
//Console output: Hello World!
//No ";" is required

let temperature = 20
let 我的常數 = 50
//Constant 常數
//Support Unicode 支援Unicode編碼 
//Type: Int  //Int整數型態(Integer)
//Initial value is required. 需要初始值
print(temperature)
print(我的常數)
// \n standards for a new line character(return to a new line)
// \n 表示換行字元
print("Add a new line character here.\n")

let helloStr = "Hello"
print(helloStr)

//Characters included in two quotation marks are known as a string. For example, "Yes" is a string.
//引號內所包含的字元稱為字串,例如,"Yes"是個字串

var mystr = "Hi ABC"
//Variable 變數
//Type: String //字串型態(Integer)
//Initial value is required. //需要初始值

//Swift 1:
//println("I want to say: \(mystr)")
//Swift 2:
print("I want to say: \(mystr)")
//Console output: I want to say: Hi ABC

mystr += "DE"
//mystr becomes "Hi ABCDE"
//Strings may be "added"

//Swift 1:
//println("I want to say: \(mystr)")
//Swift 2:
print("I want to say: \(mystr)")

//Comments will not be executed by the compiler.
//註解不會被編譯器執行

//單行註解
//Single-line comment 

//多行註解
/* Multiple-line
   Comment */

/* Nested
/* Multiline */
   Comments  */
//This is different from C. 巢狀註解
//Good design for quick debugging

//Strings may be joined together with the + sign
//可用+號將字串連接起來
let word1 = "The"
let word2 = "End"
print(word1 + " " + word2)