代码写界面的工厂类
Posted Nuius
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了代码写界面的工厂类相关的知识,希望对你有一定的参考价值。
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface DLUIKit : NSObject #pragma mark --------- UILabel -------- /** Label 字色 字号 */ + (UILabel *)labelTextColor:(UIColor *)textColor fontSize:(CGFloat)size; /** Label 文字 字号 */ + (UILabel *)labelWithText:(NSString *)text fontSize:(CGFloat)size; /** Label 字色 行数 文字 字号 */ + (UILabel *)labelWithTextColor:(UIColor *)textColor numberOfLines:(NSInteger)numberOfLines text:(NSString *)text fontSize:(CGFloat)size; /** Label 背景色 字色 对其 行数 文字 字号 */ + (UILabel *)labelWithBackgroundColor:(UIColor *)backgroundColor textColor:(UIColor *)textColor textAlignment:(NSTextAlignment)textAlignment numberOfLines:(NSInteger)numberOfLines text:(NSString *)text fontSize:(CGFloat)size; #pragma mark --------- UIImageView -------- /** ImageView 图片 */ + (UIImageView *)imageViewWithImage:(UIImage *)image; /** ImageView 图片 交互 */ + (UIImageView *)imageViewWithImage:(UIImage *)image userInteractionEnabled:(BOOL)enabled; /** ImageView 填充方式 图片 */ + (UIImageView *)imageViewWithContentMode:(UIViewContentMode)mode image:(UIImage *)image; /** ImageView 填充方式 交互 图片 */ + (UIImageView *)imageViewWithContentMode:(UIViewContentMode)mode userInteractionEnabled:(BOOL)enabled image:(UIImage *)image; #pragma mark --------- UIButton -------- /** UIButton 前景图 */ + (UIButton *)buttonWithImage:(UIImage *)image; /** UIButton 背景色 标题色 标题 字号 */ + (UIButton *)buttonWithBackgroundColor:(UIColor *)backgroundColor titleColor:(UIColor *)titleColor title:(NSString *)title fontSize:(CGFloat)size; /** UIButton 背景色 标题色 标题高亮色 标题 字号 */ + (UIButton *)buttonWithBackgroundColor:(UIColor *)backgroundColor titleColor:(UIColor *)titleColor titleHighlightColor:(UIColor *)titleHighlightColor title:(NSString *)title fontSize:(CGFloat)size; #pragma mark --------- TableView -------- + (UITableView *)tableViewWithFrame:(CGRect)frame style:(UITableViewStyle)style delegate:(id)delegate; + (void)dl_tableView:(UITableView *)tableView withDelegate:(id)delegate; @end
#import "DLUIKit.h" @implementation DLUIKit #pragma mark --------- Label -------- + (UILabel *)labelTextColor:(UIColor *)textColor fontSize:(CGFloat)size { return [SJUIKit labelWithBackgroundColor:[UIColor clearColor] textColor:textColor textAlignment:NSTextAlignmentLeft numberOfLines:1 text:nil fontSize:size]; } + (UILabel *)labelWithText:(NSString *)text fontSize:(CGFloat)size { return [SJUIKit labelWithBackgroundColor:[UIColor clearColor] textColor:[UIColor blackColor] textAlignment:NSTextAlignmentLeft numberOfLines:1 text:text fontSize:size]; } + (UILabel *)labelWithTextColor:(UIColor *)textColor numberOfLines:(NSInteger)numberOfLines text:(NSString *)text fontSize:(CGFloat)size { return [SJUIKit labelWithBackgroundColor:[UIColor clearColor] textColor:textColor textAlignment:NSTextAlignmentLeft numberOfLines:numberOfLines text:text fontSize:size]; } + (UILabel *)labelWithBackgroundColor:(UIColor *)backgroundColor textColor:(UIColor *)textColor textAlignment:(NSTextAlignment)textAlignment numberOfLines:(NSInteger)numberOfLines text:(NSString *)text fontSize:(CGFloat)size { UILabel *label = [[UILabel alloc] init]; label.backgroundColor = backgroundColor; label.textColor = textColor; label.textAlignment = textAlignment; label.numberOfLines = numberOfLines; label.text = text; label.font = [UIFont systemFontOfSize:size]; return label; } #pragma mark --------- ImageView -------- + (UIImageView *)imageViewWithImage:(UIImage *)image { return [SJUIKit imageViewWithContentMode:UIViewContentModeScaleToFill userInteractionEnabled:NO image:image]; } + (UIImageView *)imageViewWithImage:(UIImage *)image userInteractionEnabled:(BOOL)enabled { return [SJUIKit imageViewWithContentMode:UIViewContentModeScaleToFill userInteractionEnabled:enabled image:image]; } + (UIImageView *)imageViewWithContentMode:(UIViewContentMode)mode image:(UIImage *)image { return [SJUIKit imageViewWithContentMode:mode userInteractionEnabled:NO image:image]; } + (UIImageView *)imageViewWithContentMode:(UIViewContentMode)mode userInteractionEnabled:(BOOL)enabled image:(UIImage *)image { UIImageView *imageView = [[UIImageView alloc] init]; imageView.contentMode = mode; imageView.userInteractionEnabled = enabled; imageView.image = image; return imageView; } #pragma mark --------- UIButton -------- + (UIButton *)buttonWithImage:(UIImage *)image { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn setImage:image forState:UIControlStateNormal]; return btn; } + (UIButton *)buttonWithBackgroundColor:(UIColor *)backgroundColor titleColor:(UIColor *)titleColor title:(NSString *)title fontSize:(CGFloat)size { return [SJUIKit buttonWithBackgroundColor:backgroundColor titleColor:titleColor titleHighlightColor:titleColor title:title fontSize:size]; } + (UIButton *)buttonWithBackgroundColor:(UIColor *)backgroundColor titleColor:(UIColor *)titleColor titleHighlightColor:(UIColor *)titleHighlightColor title:(NSString *)title fontSize:(CGFloat)size { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.backgroundColor = backgroundColor; [btn setTitleColor:titleColor forState:UIControlStateNormal]; [btn setTitleColor:titleHighlightColor forState:UIControlStateHighlighted]; [btn setTitle:title forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:size]; btn.adjustsImageWhenHighlighted = NO; return btn; } + (UITableView *)tableViewWithFrame:(CGRect)frame style:(UITableViewStyle)style delegate:(id)delegate { UITableView *tableView = [[UITableView alloc] initWithFrame:frame style:style]; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.delegate = delegate; tableView.dataSource = delegate; tableView.backgroundColor = [UIColor whiteColor]; UIView *footerView = [[UIView alloc] init]; tableView.tableFooterView = footerView; return tableView; } + (void)dl_tableView:(UITableView *)tableView withDelegate:(id)delegate { tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.delegate = delegate; tableView.dataSource = delegate; tableView.backgroundColor = [UIColor whiteColor]; UIView *footerView = [[UIView alloc] init]; tableView.tableFooterView = footerView; } @end
以上是关于代码写界面的工厂类的主要内容,如果未能解决你的问题,请参考以下文章
uiautomator 仿 WebDriver 封装,页面工厂制作,实现多语言定位