zoukankan      html  css  js  c++  java
  • 代码写界面的工厂类

    #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
  • 相关阅读:
    基于视网膜虹膜识别的内容分级系统
    C# 反射详解一
    C# 委托浅析
    .Net Core中使用Dapper构建泛型仓储
    C# 泛型详解
    非对称可逆加密RSA
    对称可逆加密Des
    .NET Core 3.0 中间件 Middleware
    .NET Core3.0 日志 logging
    .Net Core3.0依赖注入DI
  • 原文地址:https://www.cnblogs.com/iOSDeng/p/6121431.html
Copyright © 2011-2022 走看看