★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-cipogimg-hm.html
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html
目錄:[Swift]通天遁地Swiftios
本文將演示建立一個卡片頁面,經過上下滑動進行頁面的切換。git
能夠做爲產品、酒店、旅遊景點等的介紹頁面。github
首先確保已經安裝了所需的第三方類庫。雙擊查看安裝配置文件【Podfile】 swift
1 platform :ios, ‘12.0’ 2 use_frameworks! 3 4 target 'DemoApp' do 5 source 'https://github.com/CocoaPods/Specs.git' 6 pod 'expanding-collection' 7 end
根據配置文件中的相關設置,安裝第三方類庫。微信
GitHub項目:【Ramotion/expanding-collection】,下載並解壓文件。app
【DemoExpandingCollection】->編輯器
【Constants】文件夾ide
【Helpers】文件夾post
【ViewControllers】文件夾
【Views】文件夾
【Source】文件夾
->將選擇的五個文件夾拖動到項目中。在彈出的文件導入確認窗口中,點擊【Finish】
在左側的項目導航區,打開故事板文件【Main.storyboard】
選擇故事板中的視圖控制器,依次點擊:
【Editor】編輯器->【Embed In】植入->【Navigation Controller】導航控制器
將集合視圖控制器植入導航控制器。植入導航控制器。
打開檢查器設置面板,點擊屬性檢查器圖標,進入屬性設置面板。
【Status Bar】:None,空白樣式,隱藏頂部的狀態欄。
點擊故事板監聽視圖控制器,點擊身份檢查器圖標,進入身份設置面板。
【Class】:DemoViewController
點擊控件庫圖標,往故事板中插入一張圖像視圖。
進入尺寸設置面板,依次設置圖像視圖的座標和尺寸信息。
進入屬性設置面板。
【Image】:BackgroundImage
往故事板中插入一個標籤。設置標籤控件的顯示內容。
點擊顏色右側的下拉箭頭,彈出顏色預設面板,選擇設置顏色。
在左側的項目導航區,打開應用程序的代理文件【AppDelegate.swift】
須要在應用程序加載完成的方法中,對導航條的樣式進行設置。
1 import UIKit 2 3 @UIApplicationMain 4 class AppDelegate: UIResponder, UIApplicationDelegate { 5 6 var window: UIWindow? 7 8 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 9 // Override point for customization after application launch. 10 //清除導航條的背景圖片 11 UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default) 12 //清除導航條的陰影圖片 13 UINavigationBar.appearance().shadowImage = UIImage() 14 //將導航條設置爲透明 15 UINavigationBar.appearance().isTranslucent = true 16 17 //初始化一個投影對象 18 let shadow = NSShadow() 19 //依次設置投影的距離和投影的顏色。 20 shadow.shadowOffset = CGSize(width: 0, height: 2) 21 //設置導航條標題的外觀樣式 22 shadow.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1) 23 24 //設置文字的顏色爲白色 25 UINavigationBar.appearance().titleTextAttributes = [ 26 NSAttributedString.Key.foregroundColor : UIColor.white, 27 NSAttributedString.Key.shadow: shadow 28 ] 29 return true 30 } 31 32 func applicationWillResignActive(_ application: UIApplication) { 33 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 34 // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 35 } 36 37 func applicationDidEnterBackground(_ application: UIApplication) { 38 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 39 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 40 } 41 42 func applicationWillEnterForeground(_ application: UIApplication) { 43 // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 44 } 45 46 func applicationDidBecomeActive(_ application: UIApplication) { 47 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 48 } 49 50 func applicationWillTerminate(_ application: UIApplication) { 51 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 52 } 53 }