iOS 常用的巨集定義

来源:https://www.cnblogs.com/yxl-151217/archive/2019/02/21/10414451.html
-Advertisement-
Play Games

屏幕尺寸 #define kScreenWidth [UIScreen mainScreen].bounds.size.width #define kScreenHeight [UIScreen mainScreen].bounds.size.height 手機型號 #define kISiPhon ...


屏幕尺寸

#define kScreenWidth [UIScreen mainScreen].bounds.size.width

#define kScreenHeight [UIScreen mainScreen].bounds.size.height

手機型號

 #define kISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

 #define kScreenMaxLength (MAX(kScreenWidth, kScreenHeight))

 #define kScreenMinLength (MIN(kScreenWidth, kScreenHeight))

#define kISiPhone5 (kISiPhone && kScreenMaxLength == 568.0)

#define kISiPhone6 (kISiPhone && kScreenMaxLength == 667.0)
#define kISiPhone6P (kISiPhone && kScreenMaxLength == 736.0)
#define kISiPhoneX (kISiPhone && kScreenMaxLength == 812.0)
#define kISiPhoneXr (kISiPhone && kScreenMaxLength == 896.0)
#define kISiPhoneXX (kISiPhone && kScreenMaxLength > 811.0)
#define IOS8 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0)


系統版本
#define IOS810 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 10.0)
適配尺寸
//6為標準適配的,如果需要其他標準可以修改
#define kScale_W(w) ((kScreenWidth)/375) * (w)
#define kScale_H(h) (kScreenHeight/667) * (h)
//狀態欄高度
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
//狀態欄高度
#define StatusBarHeight (kISiPhoneX?44:20)
//標簽欄高度
#define kTabBarHeight (StatusBarHeight > 20 ? 83 : 49)
//導航欄高度
#define kNavBarHeight (StatusBarHeight + 44)
//安全區高度
#define kSafeAreaBottom (kISiPhoneX ? 34 : 0)

字體大小

#define kBoldFont(x) [UIFont boldSystemFontOfSize:x]
#define kFont(x) [UIFont systemFontOfSize:x]
顏色設置
//RGB格式
#define kRGB(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
//RGBA格式
#define kRGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
//隨機顏色
#define kRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

系統相關
//APP對象 (單例對象)
#define kApplication [UIApplication sharedApplication]
//主視窗 (keyWindow)
#define kKeyWindow [UIApplication sharedApplication].keyWindow
//NSUserDefaults實例化
#define kUserDefaults [NSUserDefaults standardUserDefaults]
//通知中心 (單例對象)
#define kNotificationCenter [NSNotificationCenter defaultCenter]
//發送通知
#define KPostNotification(name,obj,info) [[NSNotificationCenter defaultCenter]postNotificationName:name object:obj userInfo:info]
//APP版本號
#define kVersion [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleShortVersionString"]
//系統版本號
#define kSystemVersion [[UIDevice currentDevice] systemVersion]


 常用設置

//載入圖片
#define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
//弱引用
#define kWeakSelf(type)  __weak typeof(type) weak##type = type
//強引用
#define kStrongSelf(type)  __strong typeof(type) type = weak##type
//安全調用Block
#define kSafeBlock(blockName,...) ({!blockName ? nil : blockName(__VA_ARGS__);})
//載入xib
#define kLoadNib(nibName) [UINib nibWithNibName:nibName bundle:[NSBundle mainBundle]]
//字元串拼接
#define kStringFormat(format,...) [NSString stringWithFormat:format,##__VA_ARGS__]
//屬性快速聲明(建議使用代碼塊)
#define kPropertyString(name) @property(nonatomic,copy)NSString *name
#define kPropertyStrong(type,name) @property(nonatomic,strong)type *name
#define kPropertyAssign(name) @property(nonatomic,assign)NSInteger name
// View 圓角和加邊框
#define kViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]
// View 圓角
#define kViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]
//永久存儲對象
#define kSetUserDefaults(object, key)                                                                                                 \
({                                                                                                                                             \
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];                                                                         \
[defaults setObject:object forKey:key];                                                                                                    \
[defaults synchronize];                                                                                                                    \
})
//獲取對象
#define kGetUserDefaults(key) [[NSUserDefaults standardUserDefaults] objectForKey:key]
//刪除某一個對象
#define kRemoveUserDefaults(key)                                         \
({                                                                          \
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];       \
[defaults removeObjectForKey:_key];                                     \
[defaults synchronize];                                                 \
})
//清除 NSUserDefaults 保存的所有數據
#define kRemoveAllUserDefaults  [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]]

日期時間
//獲得當前的年份
#define  kCurrentYear [[NSCalendar currentCalendar] component:NSCalendarUnitYear fromDate:[NSDate date]]
//獲得當前的月份
#define  kCurrentMonth [[NSCalendar currentCalendar] component:NSCalendarUnitMonth fromDate:[NSDate date]]
//獲得當前的日期
#define  kCurrentDay  [[NSCalendar currentCalendar] component:NSCalendarUnitDay fromDate:[NSDate date]]
//獲得當前的小時
#define  kCurrentHour [[NSCalendar currentCalendar] component:NSCalendarUnitHour fromDate:[NSDate date]]
//獲得當前的分
#define  kCurrentMin [[NSCalendar currentCalendar] component:NSCalendarUnitMinute fromDate:[NSDate date]]
//獲得當前的秒
#define  kCurrentSec [[NSCalendar currentCalendar] component:NSCalendarUnitSecond fromDate:[NSDate date]]

沙河路徑

//獲取沙盒 temp
#define kPathTemp NSTemporaryDirectory()
//獲取沙盒 Document
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//獲取沙盒 Cache
#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
//Library/Caches 文件路徑
#define kFilePath ([[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil])


 

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 一 資料庫和資料庫實例 在MySQL的學習研究中,存在兩個非常容易混淆的概念,即資料庫和資料庫實例。在MySQL中,資料庫和資料庫實例定義如下: 資料庫:存儲數據的集合; 資料庫實例:操作資料庫的集合。 如上定義很清楚了,資料庫是用來存儲數據的,資料庫實例是用來操作數據的,從操作系統的角度,資料庫實 ...
  • 表結構為: 表數據為: 表中數據可以看到name列中有兩行數據是一致的,去重的SQL語句為: 去重後的數據為: 總結 在進行去重時,資料庫無法進行邊查詢邊刪除,所以刪除的時候必須是第三張臨時表作為匹配刪除,這樣的操作可以省略創建臨時表直接刪除原表中數據,推薦這種方式進行去重操作。 ...
  • 在視窗1開通一個名為 redis 的通道: 從視窗2傳入信息: 此時視窗1會收到這條信息: 以上, 就是通過 SUBSCRIBE 和 PUBLISH 實現了一個簡單的消息傳遞的過程. 目前我們是有一個視窗開通 redis 通道, 另一個視窗向這個通道傳遞消息, 大家可以試下再多開一個視窗, 也開通 ...
  • ordered set 是根據 score值有序排列的數據集合. 首先還是清空數據, 並清屏, 此步驟省略~~~~ 新建一條 ordered set 數據 myset1, 並存入4個字元串, score 的排列順序為1-4: 查看這個數據: 給 myset1 的值里新加一個字元e, score=10 ...
  • INSERT INTO table SELECT * FROM OPENDATASOURCE ('SQLOLEDB', 'Data Source=172.168.44.146;User ID=sa;password=123' ).tableexec sp_configure 'show advanc ...
  • unordered collection of unique strings.set值是唯一的字元串的無序集合, 把握住兩個特點: 唯一, 無序. 清空所有的數據, 並清理顯示界面: 保存一條 set 數據, 鍵是 myset1, 值是 1, 2, 3, 4 四個數字: 查看鍵myset1 的值: ...
  • select * from dba_jobs ;select * from dba_scheduler_job_run_details t; >這個語句通過制定job名,來查看job的運行的詳細信息 select * from dba_scheduler_jobs; >這個語句可以查看所有job,及 ...
  • 正如前面所講的, redis 的數據結構就是一系列的鍵值對鍵 -> printable ASCII (可列印的 ASCII 碼, 最大值是 512MB)值 -> Primitives (基本的) string 字元串 (最大值是 512MB) Containers (of string) (以其他形 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...