“3PTS” 是一款用于记录篮球三分球练习成绩的小程序。
Swift
相关术语:
- UIKit is the iOS user interface toolkit.
- IB is Interface Builder.
- CA is Core Animation. Like CALayer is a Core Animation data type responsible for managing the way your view looks. Core Animation handles animation.
- CG is Apple’s Core Graphics framework. Like CGColor. Core Graphics handles drawing.
- KVO is key-value observing.
- NS is Next Step. Steve Jobs did lots.
- VFL is a technique called Auto Layout Visual Format Language.
- GCD is Grand Central Dispatch.
- FIFO is First In, First Out.
- MK is Mapkit.
- NS came from the NeXTSTEP libraries Foundation and AppKit(those names are still used by Apple’s Cocoa frameworks).
- UN is UserNotification.
- CL is CoreLocation.
- MC is Multipeer Connectivity.
- CM is Core Motion.
- LA is the Local Authentication framework.
- HSB is Hue, Saturation and Brightness. Using this method of creating colors you specify values between 0 and 1 to control how saturated a color is (from 0 = gray to 1 = pure color) and brightness (from 0 = black to 1 = maximum brightness), and 0 to 1 for hue. “Hue” is a value from 0 to 1 also, but it represents a position on a color wheel, like using a color picker on your Mac. Hues 0 and 1 both represent red, with all other colors lying in between.
- CK is CloudKit.
- XCTest may be XCode Test.
String
A string is a collection of character.
1 | let pizzaJoint = "café pesto" |
NSAttributedString
Attributed strings are made up of two parts: a plain Swift string, plus a dictionary containing a series of attributes that describe how various segments of the string are formatted.
NSAttributedString可以针对一串字符串,片段化地设置其的属性,而Label却只能整个设置。
我们在使用UILabel, UITextField, UITextView, UIButton, UINavigationBar等等支持text属性的情况下,更建议使用attributedText。
1 | NSAttributedString(string: String, attributes: [NSAttributedString.Key: Any]?) |
The examples are in codes below.
SwiftUI
String
components(seperatedBy:)
1 | let input = "a b c" |
trimmingCharacters(in:)
we can ask Swift to trim all whitespace at the start and end of a string like this:
1 | let trimmed = someString.trimmingCharacters(in: .whitespacesAndNewlines) |
读取txt文件中的内容,并转化成String
1 | // 例如读取项目中的start.txt文本文件中的内容, |
NSRange && rangeOfMisspelledWord && NSNotFound
1 | // rangeOfMisspelledWord: |