ios常使用的巨集定義

2021-07-11 07:34:35 字數 1391 閱讀 3185

專案中經常有一些重複使用的**,有時我們會將其巨集定義,以便快捷使用。

1.rgb顏色值轉換成uicolor物件

//顏色轉換

#define color(r,g,b,a) [uicolor colorwithred:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

2.十六進製制顏色轉換成

uicolor物件

#define uicolorfromrgb(rgbvalue) [uicolor colorwithred:((float)((rgbvalue & 0xff0000) >> 16))/255.0 green:((float)((rgbvalue & 0xff00) >> 8))/255.0 blue:((float)(rgbvalue & 0xff))/255.0 alpha:1.0]

3.判斷裝置和螢幕

#define is_ipad (ui_user_inte***ce_idiom() == uiuserinte***ceidiompad)

#define is_iphone (ui_user_inte***ce_idiom() == uiuserinte***ceidiomphone)

#define is_retina ([[uiscreen mainscreen] scale] >= 2.0)

//獲取螢幕 寬度、高度

#define screen_width ([uiscreen mainscreen].bounds.size.width)

#define screen_height ([uiscreen mainscreen].bounds.size.height)

#define screen_max_length (max(screen_width, screen_height))

#define screen_min_length (min(screen_width, screen_height))

#define is_iphone_4_or_less (is_iphone && screen_max_length < 568.0)

#define is_iphone_5 (is_iphone && screen_max_length == 568.0)

#define is_iphone_5_or_less (is_iphone && screen_max_length <= 568.0)

#define is_iphone_6 (is_iphone && screen_max_length == 667.0)

#define is_iphone_6p (is_iphone && screen_max_length == 736.0)

ios 巨集定義

這個不是ios 應該算是c裡面的 巨集定義巨集定義是c提供的三種預處理功能的其中一種,這三種預處理包括 巨集定義 檔案包含 條件編譯。1 編輯本段引數 不帶引數 巨集定義又稱為巨集代換 巨集替換,簡稱 巨集 格式 define識別符號字串 其中的識別符號就是所謂的符號常量,也稱為 巨集名 預處理 預...

iOS常用巨集定義

獲取當前螢幕的寬高 define kscreenw uiscreen mainscreen bounds size.width define kscreenh uiscreen mainscreen bounds size.height 判斷當前系統版本 define ios9 uidevice c...

ios 巨集定義除錯

nslog遮蔽輸出 使用nslog的乙個風險是 它的執行會占用時間和裝置資源。當我們用simulator時,nslog的資源占用並不引人注意,風險也不會顯示出來。但是如果你寫的是乙個即時戰略遊戲,而你在每乙個action中都加入了nslog 那麼nslog將成為乙個魔鬼。災難的具體表現常常是 你在s...