在SwiftUI中,你可以通过视图(Views)来构建 UI,然后通过修饰器(Modifiers)来改变这些视图。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
let configuration = URLSessionConfiguration.default | |
configuration.timeoutIntervalForRequest = 30 | |
configuration.allowsCellularAccess = false | |
configuration.httpAdditionalHeaders = ["Accept": "application/json"] | |
let session = URLSession(configuration: configuration) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let progressQueue = DispatchQueue(label: "com.alamofire.progressQueue", qos: .utility) | |
AF.download("https://httpbin.org/image/png") | |
.downloadProgress(queue: progressQueue) { progress in | |
print("Download Progress: \(progress.fractionCompleted)") | |
} | |
.responseData { response in | |
if let data = response.value { | |
let image = UIImage(data: data) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct OnAppear_Intro: View { | |
@State var username: String = "" | |
@State var password: String = "" | |
@State var loading: Bool = false | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct DragGesture_Intro: View { | |
@State var offset: CGFloat = 200 | |
var body: some View { | |
VStack { | |
Spacer() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct Delay_Intro: View { | |
@State var changed: Bool = false | |
var body: some View { | |
Button("开始") { | |
changed.toggle() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct AnimationOption_RepeatCount_Intro: View { | |
@State var changed: Bool = false | |
var body: some View { | |
Circle() | |
.fill(.green) | |
.frame(width: 100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func favorite(asset: PHAsset) { | |
PHPhotoLibrary.shared().performChanges({ | |
let request = PHAssetChangeRequest(for: asset) | |
request.isFavorite = !asset.isFavorite | |
}) { success, error in | |
if success { | |
print("执行成功") | |
} else if let error = error { | |
print("执行失败: \(error)") | |
} |
OlderNewer