You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

377 lines
11 KiB

//
// UICommon.h
// ChineseAgri-businesses
//
// Created by ecell on 2022/6/27.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
typedef enum : NSInteger
{
PYUIdirectionTop = 0,
PYUIdirectionBotton,
PYUIdirectionLeft,
PYUIdirectionRight,
}PYUIdirection;
@interface UICommon : NSObject
/// 快速创建UIView
/// @param rect 坐标
/// @param backColor 背景颜色
/// @param cornerRadius 圆角大小
/// @param borderWidth 边框
/// @param borderColor 边框颜色
+ (UIView *)ui_view:(CGRect)rect
backgroundColor:(UIColor *)backColor
cornerRadius:(CGFloat)cornerRadius
borderWidth:(CGFloat)borderWidth
borderColor:(UIColor *)borderColor;
/// 快速创建UILabel
/// @param rect 坐标
/// @param line 行数
/// @param align 字体位置
/// @param font 字体
/// @param textColor 字体颜色
/// @param text 内容
/// @param Radius 圆角大小
+ (UILabel *)ui_label:(CGRect)rect
lines:(NSInteger)line
align:(NSTextAlignment)align
font:(UIFont *)font
textColor:(UIColor *)textColor
text:(NSString *)text
Radius:(CGFloat)Radius;
/**
创建textView
@param rect 尺寸大小
@param textColor 文本颜色
@param font 字体
@param alignment 对齐方式
@param inputView 附加视图
@return 对象
*/
+ (UITextView *)ui_textView:(CGRect)rect textColor:(UIColor *)textColor backColor:(UIColor *)backColor font:(UIFont *)font alignment:(NSTextAlignment)alignment inputView:(UIView *)inputView;
/// 快速创建UIButton
/// @param rect 坐标
/// @param font 字体
/// @param normalColor 字体颜色
/// @param normalText 文字
/// @param click 点击事件
+ (UIButton *)ui_buttonSimple:(CGRect)rect
font:(UIFont *)font
normalColor:(UIColor *)normalColor
normalText:(NSString *)normalText
click:(void (^)(id x))click;
/**
创建tableView
@param rect 尺寸大小
@param style 样式
@param backColor 背景颜色
@param sth 代理对象
@param registerDic 注册内容
@return 对象
*/
+ (UITableView *)ui_tableView:(CGRect)rect style:(UITableViewStyle)style backColor:(UIColor *)backColor delegate:(id)sth registerDic:(NSDictionary *)registerDic;
/// 创建指定圆角视图
/// @param rect 坐标
/// @param direction 圆角方向
/// @param toview 圆角View
/// @param sizeMake 圆角大小
+(UIView *) ui_uiViewFillet:(CGRect)rect
Viewdirection:(PYUIdirection)direction
toView:(UIView *)toview
sizeMake:(CGFloat)sizeMake;
/// 指定圆角并带有颜色边框
/// @param view 需要添加效果的视图
/// @param corner 圆角位置
/// @param cornerRadius 圆角大小
/// @param width 边框宽度
/// @param color 边框颜色
+ (void)setupView:(UIView *)view
corners:(UIRectCorner)corner
cornerRadius:(CGFloat)cornerRadius
borderWidth:(CGFloat)width
borderColor:(UIColor *)color;
/// 换算时分秒
/// @param totalSeconds 秒
/// @param type 换算类型 1 时分秒 其他 分秒
+ (NSString *)timeFormatted:(NSInteger)totalSeconds
type:(int)type;
/// @param title 文字
/// @param index 变换颜色开始位
/// @param fonts 字体
/// @param colors 颜色
+ (NSAttributedString *)attributedTextWith:(NSString *)title
index:(NSInteger)index
fonts:(UIFont *)fonts
color:(UIColor *)colors;
/**
创建textField
@param rect 尺寸大小
@param backColor 背景颜色
@param font 字体大小
@param maxNum 最大数量 传0表示没有限制
@param placeholderColor 默认字体颜色
@param placeholder 默认字
@param toMaxNum 设置了最大数量后回调
@param change 监听内容改变
@return 对象
*/
+ (UITextField *)ui_textField:(CGRect)rect
textColor:(UIColor *)textColor
backColor:(UIColor *)backColor
font:(UIFont *)font
maxTextNum:(NSInteger)maxNum
placeholderColor:(UIColor *)placeholderColor
placeholder:(NSString *)placeholder
toMaxNum:(void(^)(UITextField *textField))toMaxNum change:(void(^)(UITextField *textField))change;
/**
创建图片
@param rect 尺寸大小
@param name 本地图片名称 传nil则不赋值
@return 对象
*/
+ (UIImageView *)ui_imageView:(CGRect)rect fileName:(NSString *)name;
/// 颜色转Image
/// @param color 颜色
+ (UIImage*)createImageWithColor:(UIColor*)color;
/// UIlabel 某个位置文字多种颜色
/// @param title 文字
/// @param index 变换颜色开始位
/// @param toindex 结束位
/// @param fonts 字体
/// @param colors 颜色
/// @param tocolors 其他字段颜色
/// @param line 间距
/// @param TextAlignment 字体位置
+ (NSAttributedString *)attributedTextWiths:(NSString *)title
index:(NSInteger)index
toindex:(NSInteger)toindex
fonts:(UIFont *)fonts
color:(UIColor *)colors
tocolor:(UIColor *)tocolors
line:(CGFloat)line
TextAlignment:(NSTextAlignment)TextAlignment;
+ (NSString *)getShowDateWithTime:(NSString *)time;
+ (void)BtnLaye:(UIButton *)btn colors:(UIColor *)BtnColor BtnRadius:(CGFloat)BtnRadius;
/// 成功提示框
/// @param text 提示问题
+ (void)MessageSuccessText:(NSString *)text;
/// 错误提示框
/// @param text 提示文字
+ (void)MessageErrorText:(NSString *)text;
/// 加载提示框
/// @param text 提示文字
+ (void)MessageUpload:(NSString *)text;
/// 隐藏提示框
+ (void)HidenLoading;
/// 指定字符大小
/// @param text 内容
+ (NSAttributedString *)labelFontSize:(NSString *)text;
/// 画删除线
/// @param label label
+ (void)drawLine:(UILabel *)label;
+ (void)drawLine_ll:(UILabel *)label;
+ (UIViewController *)currentVC;
+ (void)setBtnUpImageDownTitle:(UIButton *)btn;
/// 之间戳转换成时间
/// @param time 时间戳
/// @param type 默认 年月日时分秒 MM:月日时分秒 DD:日时分秒 HH:时分秒
+ (NSString *)getTimeFromTimestamp:(NSString *)time type:(NSString *)type;
/// 之间戳转换成时间
/// @param time 时间戳
+ (NSString *)getTimeFromTimestamp_n:(NSString *)time;
/// 获取当前月的下一个月到某个日期内的所有月份
/// @param fromDateStr 起始月份 不传则获取半年内的月份
+ (NSArray *)returnSixYearAndMonth:(NSString*)fromDateStr;
/// 获取月份
/// @param monthNum -1为当前月份的前一个月,1为后一个月,以此类推
+ (NSString *)setupRequestMonth:(NSInteger)monthNum;
+ (NSMutableAttributedString *)zuheWithMoney:(double)money;
//根据颜色返回图片
+(UIImage*) imageWithColor:(UIColor*)color;
/// 划虚线
+ (void)xuxian:(UIView *)view;
/// 指定字符颜色
/// @param text 内容
+ (NSAttributedString *)giftlabelTextColor:(NSString *)text;
+ (NSString *)giftImage:(NSInteger)row;
+ (NSString *)giftTitle:(NSInteger)row;
/// json转字典
/// @param jsonString json
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString;
/// 字典转json
/// @param dic 字典
+ (NSString*)dictionaryToJson:(NSDictionary *)dic;
/// 判断字符串是否是json
/// @param jsonString 字符串
+ (BOOL)isJsonString:(NSString *)jsonString;
+ (void)setExtraCellLineHidden:(UITableView *)tableView;
+ (void)setTavleViewlink:(UITableView *)tableview
distance:(CGFloat)distance;
/// 颜色渐变
+ (UIColor *)setGradientBackgroundColor:(UIColor *)Color1
Color2:(UIColor *)Color2
Width:(CGFloat)Width
Height:(CGFloat)Height;
/// 颜色渐变
+ (UIImage *)setGradientBackgroundImg:(UIColor *)Color1
Color2:(UIColor *)Color2
Width:(CGFloat)Width
Height:(CGFloat)Height;
void AfterDispatch(double delayInSeconds, dispatch_block_t _Nullable block);
//获取八位数code
+ (NSString *)getRandomEightCode;
/// 震动反馈
+ (void)feedbackGenerator;
// 消除键盘
+ (void)resignKeyboard;
/// 给UITextField设置左右侧的图片
/// @param textField textField
/// @param leftImageName 左侧UIImageView图片名称
/// @param rightImageName 右侧UIButton图片名称
/// @param click 右侧UIButton点击事件回调
+ (void)setRightViewWithTextField:(UITextField *_Nullable)textField
leftImageName:(NSString *_Nullable)leftImageName
rightImageName:(NSString *_Nullable)rightImageName
click:(void (^)(UITextField *textField))click;
#pragma mark 二维码 URL获取 参数
+ (NSMutableDictionary *_Nullable)getDicWithUrl:(NSString *_Nullable)urlStr;
/**
获取 关系名字数组
*/
+(NSArray *_Nullable)getRelationshipNameArr:(NSInteger)deviceType;
/**
获取 关系未选中的图片数组
*/
+(NSArray *_Nullable)getUnclickRelationshipImageArr:(NSInteger)deviceType;
/**
获取 关系选中的图片数组
*/
+(NSArray *_Nullable)getClickRelationshipImageArr:(NSInteger)deviceType;
/**
根据 关系id 获取 关系名字
*/
+(NSString *_Nullable)getRelationshipNameWithCodeID:(NSInteger)code deviceType:(NSInteger)deviceType;
/**
根据 关系id 获取 关系未选中的图片
*/
+(UIImage *_Nullable)getUnclickRelationshipImageWithCodeID:(NSInteger)code deviceType:(NSInteger)deviceType;
/**
根据 关系id 获取 关系选中的图片
*/
+(UIImage *_Nullable)getClickRelationshipImageWithCodeID:(NSInteger)code deviceType:(NSInteger)deviceType;
//获取当前系统时间
+ (NSString *_Nonnull)getSysTime;
/// 根据电量获取电量图片
/// - Parameter number: 电量
+ (UIImage *)GetElectricityImg:(NSInteger)number;
+ (NSString *)getDateFormatWithStr:(NSString *)dateFormat timeInterval:(NSTimeInterval)timeInterval;
+ (NSDate *)getDateWithStr:(NSString *)dateString dateFormat:(NSString *)dateFormat;
+ (NSString *)getDateFormatWithStr:(NSString *)dateFormat date:(NSDate *)date;
+ (NSMutableArray *)getWeekStr:(NSString *)string;
// 获取文字宽度、高度
/// - Parameters:
/// - text: 需要计算的文字
/// - heights: 控件高度
/// - size: 文字大小
/// - type: w/W:宽度 ,h/H:高度
+ (CGRect)GetTextWidth:(NSString *)text ViewHeight:(CGFloat)heights fontSize:(UIFont *)size type:(NSString *)type;
+ (NSDate*)getTimeStrWithString:(NSString*)str;
/// 图片质量压缩
+(UIImage *)reduceImage:(UIImage *)image percent:(float)percent;
/// 设置按钮文字在图片的下面
+ (void)setTitleAndImage:(UIButton *)btn :(CGFloat)heights;
/// 设置cell第一行和最后一行圆角
/// - Parameters:
/// - tableView: UITableView
/// - cell: cell
/// - indexPath: indexPath
/// - coutn: 总行数
/// - sizeH: 左右边距
+ (void)tableView:(UITableView *)tableView
willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
cellCoutn:(NSInteger)coutn
sizeH:(CGFloat)sizeH;
@end