Sagit.Framework For IOS 自动布局教程:11、常用宏定义:frame坐标系、获取UI、UI取值、字体颜色、图片

1年前 (2023) 程序员胖胖胖虎阿
112 0 0

前言:

本篇介绍一些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 中的定义。

 

相关文章

暂无评论

暂无评论...