The beginning IOS8 programming with Swift Chinese translation-6

Source: Internet
Author: User

Continue to type the following line of code: Then the previous code writes:

Message2.lowercasestring + "Okay, I ' m working on it"

Swift allows to concatenate-strings with the + operator. The line of code converts the content of Message2 to lower case and then concatenated with another string. Interestingly, you can include emoji characters in your code. Wonder how to type emoji characters in Mac OS. It ' s easy. Just Press Control-command-spacebar and an emoji picker would be displayed.

Swift allows you to connect two strings with A +. The newly written code converts the Message2 text to lowercase and then joins the other string. Interestingly, you can connect emoticons in your code. You might want to know how to play emoji in Mac OS. In fact, it is very simple, just need to control command plus the space bar, you can let the emoji selector display.

Let's continue to type the following code snippet: Lets go ahead and write the code (the method of printing in the book is println (), but then the Apple changes to print (), so I'm going to write it in the latest )

if message1 = = message2{

Print ("same message")

}else{

Print ("Not the same message")

}

Conditional logic is very common in programming. Sometimes, you want-to-execute certain part of the code only if a certain condition is met. An if-else statement are one of the ways in Swift-control program flow. Here we compare the content of Message1 and message2 variables using the = = operator. If they ' re equal, the program prints "same message". Otherwise, it prints "not the same message". You should see the following result on your.

Logical judgment statements are very easy to see in the development. Sometimes you just want to execute a piece of code when certain conditions are met, and If-else is one way to execute the control flow in Swift. In this code we use = = to compare the text of Message1 and Message2. If they are equal, print "same message", and if so, print "not same message" and you will see the results on your screen.

Let ' s has some more fun and create a label, which is a common user interface element: Lets create a Label control and get some pleasure from it, this kind of control is very common A control that interacts with the user.

Let Messagelabel = UILabel (Frame:cgrect (x:0,y:0,width:300,height:50)) PS: This book is created in the following way: UILabel (frame:cgrectmake (0, 0, 300, 50))

Messagelabel.text = Message1

Messagelabel

Here we use a built-in UILabel class to create a label and set it size to 300x50 points. We then set their text to Message1. To preview a UI element in Playground, you can click the "Quick look" or Value history icon. The Quick look feature displays the label as a pop-over. If you use the Value of the history feature, Playground opens a separate preview pane.

Here we create a label control, and set his width to 300 high for 50, then we set the text that he displayed as Message1. If you want to preview the control in playground, you can click on the Quick View or the numeric history image. A quick view of how the control is displayed is the pop-up window. If you use the numeric history feature, then playground will open a separate window.

It ' s just a plain label. Wouldn ' is great if can change it color? Even better, you just need one line of code to customize the color. What's more you can easily center the text and change the label to round corner. Type the following lines and you'll see a rounded corner label with orange background.

This is just a simple label, if you can change his color you will not feel very dick? What's more, you just need to add a line of code to customize his color. There is also you can easily change the position of his text, let the text center, let the label Corner circle. Typing the following code you will see a rounded label with an orange background color;

Messagelabel.backgroundcolor = Uicolor.orangecolor ()

Messagelabel.textalignment = Nstextalignment.center

MessageLabel.layer.cornerRadius = 10.0

Messagelabel.clipstobounds = True

Messagelabel

This is the power of the IOS SDK. It comes with tons of pre-built elements and allows developers to customize them with few lines of code.

That's the point of the iOS SDK. He provides a large number of pre-built controls and allows developers to customize them with just a few lines of code

Don ' t get me wrong. Typically you don't need to write code to create the user interface. Xcode provides a Storyboard feature that lets you design UI using Drag-and-drop. We ' ll go through in the next chapter.

Don't get me wrong about what I mean. In fact, you don't need to use code to create your interactive interface. Xcode provides storyboard to allow you to design interactive pages in a drag-and-drop fashion. We'll explain in the next chapter.

So you ' ve got a taste of Swift? What does you think? Love it? I hope you find Swift a lot easier to learn and code. Most importantly, I hope it's don ' t scare you away from learning app development. Next up, you'll learn how to build your first app.

So have you experienced swift now? What do you think? Are you in love with him? I hope you can find that he is very easy to learn and write. Most importantly, I hope you don't get scared by learning app development. At the end of the day, you'll start learning to create your first app in the next one.

For your reference, you can download the Playground file from Https://www.dropbox.com/s/y9plgddbsjauhqq/MyPlayground.zip ? dl=0.

You can get from https://www.dropbox.com/s/y9plgddbsjauhqq/MyPlayground.zip?dl=0. This page to download the Playgrund file as a reference.

The beginning IOS8 programming with Swift Chinese translator-6

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.