1. 程式人生 > 實用技巧 >Sagit.Framework For IOS 自動佈局教程:10、常用巨集定義:frame座標系、獲取UI、UI取值、字型顏色、圖片

Sagit.Framework For IOS 自動佈局教程:10、常用巨集定義:frame座標系、獲取UI、UI取值、字型顏色、圖片

前言:

本篇介紹一些Sagit框架定義,常用到的巨集定義。

1、座標系相關

//全屏
#define STFullRect [UIScreen mainScreen].bounds
#define STFullSize [UIScreen mainScreen].bounds.size
//空屏
#define STEmptyRect CGRectMake(0,0,0,0)

//座標系
#define STRectMake(x,y,width,height) CGRectMake(x*Xpt,y*Ypt,width*Xpt,height*Ypt)
#define STSizeMake(width,height) CGSizeMake(width*Xpt,height*Ypt)
#define
STPointMake(x,y) CGPointMake(x*Xpt,y*Ypt) #define STRectCopy(frame) CGRectMake(frame.origin.x,frame.origin.y, frame.size.width, frame.size.height);

2、UIView檢視:獲取

//!定義一個可以在view和Controller中共同使用的佈局標識
#define sagit self.baseView

#endif

//上一個UI控制元件的簡寫
#define STPreView sagit.lastAddView.preView
#define
STLastView sagit.lastAddView #define STLastControl ((UIControl*)STLastView) #define STLastButton ((UIButton*)STLastView) #define STLastTextField ((UITextField*)STLastView) #define STLastTextView ((UITextView*)STLastView) #define STLastImageView ((UIImageView*)STLastView) #define STLastLabel ((UILabel*)STLastView) #define
STLastSwitch ((UISwitch*)STLastView) #define STLastStepper ((UIStepper*)STLastView) #define STLastSlider ((UISlider*)STLastView) #define STLastProgressView ((UIProgressView*)STLastView) #define STLastTableView ((UITableView*)STLastView) #define STLastCollectoinView ((UICollectionView*)STLastView) //獲取控制元件 #define STUIView(name) [sagit find:name] #define STSTView(name) ((STView*)STUIView(name)) #define STControl(name) ((UIControl*)STUIView(name)) #define STButton(name) ((UIButton*)STUIView(name)) #define STTextField(name) ((UITextField*)STUIView(name)) #define STTextView(name) ((UITextView*)STUIView(name)) #define STImageView(name) ((UIImageView*)STUIView(name)) #define STLabel(name) ((UILabel*)STUIView(name)) #define STSwitch(name) ((UISwitch*)STUIView(name)) #define STStepper(name) ((UIStepper*)STUIView(name)) #define STSlider(name) ((UISlider*)STUIView(name)) #define STProgressView(name) ((UIProgressView*)STUIView(name)) #define STTableView(name) ((UITableView*)STUIView(name)) #define STCollectionView(name) ((UICollectionView*)STUIView(name)) #define STFirstTable ((UITableView*)[sagit firstView:@"UITableView"]) #define STFirstCollection ((UICollectionView*)[sagit firstView:@"UICollectionView"])

3、UI的取值。

//獲取UI值
# define STValue(name) [STUIView(name) stValue]
# define STSetValue(name,value) [STUIView(name) stValue:value]
# define STSelectValue(name) [STUIView(name) selectValue]
# define STSelectText(name) [STUIView(name) selectText]

4、字型與顏色

//字型畫素
#define STFont(px) [UIFont systemFontOfSize:px*Ypt]
//加粗
#define STFontBold(px) [UIFont boldSystemFontOfSize:px*Ypt]
#pragma mark 顏色

//裝置顏色
#define STDeviceColor [UIColor hex:@"#f4f4f4"]//米白
//顏色
#define STColor(color) [UIColor hex:color]

#define ColorBlack [UIColor blackColor]      // 0.0 white
#define ColorBlue [UIColor blueColor]
#define ColorDarkGray [UIColor darkGrayColor]
#define ColorLightGray [UIColor lightGrayColor]
#define ColorWhite [UIColor whiteColor]
#define ColorGray [UIColor grayColor]
#define ColorRed [UIColor redColor]
#define ColorGreen [UIColor greenColor]
#define ColorCyan [UIColor cyanColor]
#define ColorYellow [UIColor yellowColor]
#define ColorMagenta [UIColor magentaColor]
#define ColorOrange [UIColor orangeColor]
#define ColorPurple [UIColor purpleColor]
#define ColorBrown [UIColor brownColor]
#define ColorClear [UIColor clearColor]
#define ColorRGB(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define ColorRandom ColorRGB(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))

5、圖片

//圖片
#define STImage(imgName) [UIImage imageNamed:imgName]
#define STImageOriginal(imgName) [[UIImage imageNamed:imgName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

總結:

回頭自己看:STDefineUI.h中的定義。