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
  • 相关阅读:
    poj 2528 Mayor's posters (线段树+离散化)
    poj 1201 Intervals (差分约束)
    hdu 4109 Instrction Arrangement (差分约束)
    poj 1195 Mobile phones (二维 树状数组)
    poj 2983 Is the Information Reliable? (差分约束)
    树状数组 讲解
    poj 2828 Buy Tickets (线段树)
    hdu 1166 敌兵布阵 (树状数组)
    Ubuntu网络配置
    Button控制窗体变量(开关控制灯的状态)
  • 原文地址:https://www.cnblogs.com/iOSDeng/p/6121431.html
Copyright © 2011-2022 走看看