#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface CreateUI : NSObject
#pragma mark viewRadius +(void)radiusWithView:(UIView *)radiusView withRadius:(CGFloat)radius;
+(void)radiuCornerWithColor:(UIView *)aView radius:(int)radius colorStr:(NSString *)colorStr; //添加下边框
+(void)addFrameWithBottomView:(UIView *)borderView borderHeight:(CGFloat)borderHiehgt withBorderColor:(NSString *)frameColorStr;
//添加右边框
+(void)addFrameWithRightView:(UIView *)borderView borderWidth:(CGFloat)borderWidth withBorderColor:(NSString *)frameColorStr;
//添加下划线,左右和父视图相等
+(void)addFrameWithBottomViewWithParentsWithView:(UIView *)view; #pragma mark UIView
+(UIView *)createViewWithBGColorStr:(NSString *)bgColorStr;
+(UIView *)createViewWithBGColorStr:(NSString *)bgColorStr withRadius:(CGFloat)radius;
/*
报表help的view
*/
+ (UIView *)createAlertViewWithTitle:(NSString *)title withContent:(NSString *)content; #pragma mark UILabel
+(UILabel *)createLabelWithTextColorStr:(NSString *)textColorStr withFontSize:(float )fontSize;
+(UILabel *)createLabelWithTextColorStr:(NSString *)textColorStr withFontSize:(float )fontSize withText:(NSString *)textStr; #pragma mark UIButton
+(UIButton *)createGraySearchBtn;
+(UIButton *)createBtnWithTile:(NSString *)titleStr withTitleColorStr:(NSString *)titleColorStr withFontSize:(CGFloat)fontsize ;
+(UIButton *)createBtnWithNormalimg:(NSString *)normalImg withSelectedImg:(NSString *)selectImag ;
+(UIButton *)createBtnWithTile:(NSString *)titleStr withTitleColorStr:(NSString *)titleColorStr withFontSize:(CGFloat)fontsize withNormalimg:(NSString *)normalImg withSelectedImg:(NSString *)selectImag; #pragma mark UITableView
+(UITableView *)createTableViewWithNoSep; #pragma mark UITextField
+(UITextField *)createTFWithPlaceholder:(NSString *)placeholder withFontsize:(CGFloat)fontsize withColorStr:(NSString *)textColor;
+(void)textfieldWith:(UITextField *)tf placeholder:(NSString *)placeholder withFontsize:(CGFloat)fontsize withColorStr:(NSString *)textColor; #pragma mark UISwitch
+(UISwitch *)createSwithWithOnBGColorStr:(NSString *)bgColorStr; @end
#import "CreateUI.h"
#import "Masonry.h"
#import "DefineStr.h"
@implementation CreateUI +(void)radiusWithView:(UIView *)radiusView withRadius:(CGFloat)radius{
radiusView.clipsToBounds = YES;
radiusView.layer.cornerRadius = radius;
}
+(void)radiuCornerWithColor:(UIView *)aView radius:(int)radius colorStr:(NSString *)colorStr{
aView.clipsToBounds = YES;
aView.layer.borderWidth = 1.0f;
aView.layer.borderColor = [DefineStr colorWithHexString:colorStr].CGColor;
aView.layer.cornerRadius = radius;
}
+(void)addFrameWithBottomView:(UIView *)borderView borderHeight:(CGFloat)borderHiehgt withBorderColor:(NSString *)frameColorStr{
UIView *line = [CreateUI createViewWithBGColorStr:frameColorStr];
[borderView addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.offset(0);
make.left.offset(0);
make.right.offset(0);
make.height.offset(borderHiehgt);
}];
}
+(void)addFrameWithRightView:(UIView *)borderView borderWidth:(CGFloat)borderWidth withBorderColor:(NSString *)frameColorStr{
UIView *line = [CreateUI createViewWithBGColorStr:frameColorStr];
[borderView addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.offset(0);
make.right.offset(0);
make.width.offset(1);
make.bottom.offset(0); }]; }
+(void)addFrameWithBottomViewWithParentsWithView:(UIView *)view{
UILabel *line = [UILabel new];
line.backgroundColor =[DefineStr colorWithHexString:@"#d6d6d6"]; [[view superview] addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(0);
make.right.offset(0);
make.height.offset(1);
make.bottom.equalTo(view.mas_bottom);
}]; }
+(UIView *)createViewWithBGColorStr:(NSString *)bgColorStr{
UIView *view = [UIView new];
view.backgroundColor = [DefineStr colorWithHexString:bgColorStr];
return view;
}
+(UIView *)createViewWithBGColorStr:(NSString *)bgColorStr withRadius:(CGFloat)radius{
UIView *view = [CreateUI createViewWithBGColorStr:bgColorStr];
[CreateUI radiusWithView:view withRadius:radius];
return view;
}
+ (UIView *)createAlertViewWithTitle:(NSString *)title withContent:(NSString *)content
{
float textWidth = 260; float textMargin = 10; UILabel *titleLabel = [[UILabel alloc]init]; titleLabel.font = [UIFont systemFontOfSize:18]; titleLabel.textColor = [UIColor blackColor]; titleLabel.backgroundColor = [UIColor clearColor]; titleLabel.lineBreakMode =NSLineBreakByWordWrapping; titleLabel.textAlignment = NSTextAlignmentCenter; titleLabel.text = title; titleLabel.frame = CGRectMake(0, textMargin, textMargin * 2 + textWidth, 40);
NSString *message = content;
UIFont *textFont = [UIFont systemFontOfSize:15]; NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = textFont; CGSize maxSize = CGSizeMake(textWidth-textMargin*2, MAXFLOAT); CGSize size = [message boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size; UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(textMargin,CGRectGetMaxY(titleLabel.frame) + textMargin,textWidth, size.height)]; textLabel.font = textFont; textLabel.textColor = [UIColor blackColor]; textLabel.backgroundColor = [UIColor clearColor]; textLabel.lineBreakMode =NSLineBreakByWordWrapping; textLabel.numberOfLines =0; textLabel.textAlignment =NSTextAlignmentLeft; textLabel.text = message; UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, textWidth + textMargin * 2,CGRectGetMaxY(textLabel.frame)+textMargin)];
[demoView addSubview:titleLabel];
[demoView addSubview:textLabel];
return demoView;
} +(UILabel *)createLabelWithTextColorStr:(NSString *)textColorStr withFontSize:(float )fontSize{
UILabel *label = [UILabel new];
label.textColor = [DefineStr colorWithHexString:textColorStr];
label.font = [UIFont systemFontOfSize:fontSize];
return label;
}
+(UILabel *)createLabelWithTextColorStr:(NSString *)textColorStr withFontSize:(float )fontSize withText:(NSString *)textStr{
UILabel *label = [CreateUI createLabelWithTextColorStr:textColorStr withFontSize:fontSize];
label.text = textStr;
return label;
} +(void)setLabelWithLabel:(UILabel *)label withStr:(NSString *)str withColor:(NSString *)colorStr withFontSize:(float)fontSize withImg:(NSString *)imgStr numberLines:(int)lines {
if(!str){
str = @"";
}
NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:str];
// 修改富文本中的不同文字的样式
[attri addAttribute:NSForegroundColorAttributeName value:[DefineStr colorWithHexString:colorStr ] range:NSMakeRange(0, str.length)];
[attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:fontSize] range:NSMakeRange(0, str.length)];
// 2.添加表情图片
NSTextAttachment *attch = [[NSTextAttachment alloc] init];
// 表情图片
attch.image = [UIImage imageNamed:imgStr];
// 设置图片大小
attch.bounds = CGRectMake(0,0, fontSize, fontSize); // 创建带有图片的富文本
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
[attri insertAttributedString:string atIndex:0];// 插入某个位置 // 用label的attributedText属性来使用富文本
label.attributedText = attri;
label.numberOfLines = lines;
} +(UIButton *)createGraySearchBtn{
UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[searchBtn setImage:[UIImage imageNamed:@"searchGray"] forState:UIControlStateNormal];
return searchBtn;
} +(UIButton *)createBtnWithTile:(NSString *)titleStr withTitleColorStr:(NSString *)titleColorStr withFontSize:(CGFloat)fontsize {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:titleStr forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont systemFontOfSize:fontsize];
[btn setTitleColor:[DefineStr colorWithHexString:titleColorStr] forState:UIControlStateNormal];
return btn; } +(UIButton *)createBtnWithTile:(NSString *)titleStr radius:(float)radius withTitleColorStr:(NSString *)titleColorStr withFontSize:(CGFloat)fontsize{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:titleStr forState:UIControlStateNormal]; btn.clipsToBounds = YES;
btn.layer.cornerRadius = radius;
btn.titleLabel.font = [UIFont systemFontOfSize:fontsize];
[btn setTitleColor:[DefineStr colorWithHexString:titleColorStr] forState:UIControlStateNormal];
return btn; } +(UIButton *)createBtnWithTile:(NSString *)titleStr withBGColorStr:(NSString *)bgColor radius:(float)radius withTitleColorStr:(NSString *)titleColorStr withFontSize:(CGFloat)fontsize{ UIButton *btn = [CreateUI createBtnWithTile:titleStr radius:radius withTitleColorStr:titleColorStr withFontSize:fontsize];
[btn setBackgroundImage:[DefineStr createImageWithColor:[DefineStr colorWithHexString:bgColor]] forState:UIControlStateNormal];
return btn;
}
+(UIButton *)createBtnWithNormalimg:(NSString *)normalImg withSelectedImg:(NSString *)selectImag {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:normalImg] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:selectImag] forState:UIControlStateSelected];
return btn;
}
+(UIButton *)createBtnWithTile:(NSString *)titleStr withTitleColorStr:(NSString *)titleColorStr withFontSize:(CGFloat)fontsize withNormalimg:(NSString *)normalImg withSelectedImg:(NSString *)selectImag {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:titleStr forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont systemFontOfSize:fontsize];
[btn setTitleColor:[DefineStr colorWithHexString:titleColorStr] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:normalImg] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:selectImag] forState:UIControlStateSelected];
return btn; } +(UITableView *)createTableViewWithNoSep{
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
tableView.tableFooterView = [UIView new];
return tableView;
}
+(UISwitch *)createSwithWithOnBGColorStr:(NSString *)bgColorStr{
UISwitch *swith = [UISwitch new];
swith.onTintColor = [DefineStr colorWithHexString:bgColorStr];
return swith;
} +(UITextField *)createTFWithPlaceholder:(NSString *)placeholder withFontsize:(CGFloat)fontsize withColorStr:(NSString *)textColor{
UITextField *field = [UITextField new];
field.placeholder = placeholder;
field.font = [UIFont systemFontOfSize:fontsize];
field.textColor = [DefineStr colorWithHexString:textColor];
return field;
}
+(void)textfieldWith:(UITextField *)field placeholder:(NSString *)placeholder withFontsize:(CGFloat)fontsize withColorStr:(NSString *)textColor{
field.placeholder = placeholder;
field.font = [UIFont systemFontOfSize:fontsize];
field.textColor = [DefineStr colorWithHexString:textColor];
} @end

OC常用控件封装的更多相关文章

  1. [WinForm]WinForm跨线程UI操作常用控件类大全

    前言 在C#开发的WinForm窗体程序开发的时候,经常会使用多线程处理一些比较耗时之类的操作.不过会有一个问题:就是涉及到跨线程操作UI元素. 相信才开始接触的人一定会遇上这个问题. 为了解决这个问 ...

  2. Xamarin Studio在Mac环境下的配置和Xamarin.iOS常用控件的示例

    看过好多帖子都是Win环境装XS,Mac只是个模拟器,讲解在Mac环境下如何配置Xamarin Studio很少,也是一点点找资料,东拼西凑才把Xamarin Studio装在Mac上跑起来,如下: ...

  3. MFC编程入门之二十二(常用控件:按钮控件Button、Radio Button和Check Box)

    本节继续讲解常用控件--按钮控件的使用. 按钮控件简介 按钮控件包括命令按钮(Button).单选按钮(Radio Button)和复选框(Check Box)等.命令按钮就是我们前面多次提到的侠义的 ...

  4. MFC编程入门之二十(常用控件:静态文本框)

    上一节讲了颜色对话框之后,关于对话框的使用和各种通用对话框的介绍就到此为止了.从本节开始将讲解各种常用控件的用法.常用控件主要包括:静态文本框.编辑框.单选按钮.复选框.分组框.列表框.组合框.图片控 ...

  5. MFC之常用控件(四)

    常用控件主要包括:静态文本框.编辑框.单选按钮.复选框.分组框.列表框.组合框.图片控件.列表控件.树形控件和进度条控件等等.本节教程先来讲解静态文本框的使用. 控件的通知消息 在将静态文本框的使用之 ...

  6. Android support library支持包常用控件介绍(二)

    谷歌官方推出Material Design 设计理念已经有段时间了,为支持更方便的实现 Material Design设计效果,官方给出了Android support design library ...

  7. VS2010/MFC编程入门之二十二(常用控件:按钮控件Button、Radio Button和Check Box)

    言归正传,鸡啄米上一节中讲了编辑框的用法,本节继续讲解常用控件--按钮控件的使用. 按钮控件简介 按钮控件包括命令按钮(Button).单选按钮(Radio Button)和复选框(Check Box ...

  8. VS2010/MFC编程入门之二十(常用控件:静态文本框)

    上一节鸡啄米讲了颜色对话框之后,关于对话框的使用和各种通用对话框的介绍就到此为止了.从本节开始鸡啄米将讲解各种常用控件的用法.常用控件主要包括:静态文本框.编辑框.单选按钮.复选框.分组框.列表框.组 ...

  9. QT_7_资源文件_对话框_QMessageBox_界面布局_常用控件

    资源文件 1.1. 将资源导入到项目下 1.2. 添加文件—>Qt -->Qt Resource File 1.3. 起名称 res ,生成res.qrc文件 1.4. 右键 open i ...

随机推荐

  1. Tomcat容器做到自我保护,设置最大连接数(服务限流:tomcat请求数限制)

    http://itindex.net/detail/58707-%E5%81%87%E6%AD%BB-tomcat-%E5%AE%B9%E5%99%A8 为了确保服务不会被过多的http长连接压垮,我 ...

  2. 【QT】error: 'SIGNAL' was not declared in this scope

    error: 'SIGNAL' was not declared in this scope  未在此范围内声明. connect(ui->Btnshowhello,SIGNAL(clicked ...

  3. [Bayes] Hist & line: Reject Sampling and Importance Sampling

    吻合度蛮高,但不光滑. > L= > K=/ > x=runif(L) > *x*(-x)^/K)) > hist(x[ind],probability=T, + xla ...

  4. Linux设备驱动剖析之IIC(四)

    558行,又重试2次. 560行,调用s3c24xx_i2c_doxfer函数: static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, stru ...

  5. 在一个由 'L' , 'R' 和 'X' 三个字符组成的字符串(例如"RXXLRXRXL")中进行移动操作。一次移动操作指用一个"LX"替换一个"XL",或者用一个"XR"替换一个"RX"。现给定起始字符串start和结束字符串end,请编写代码,当且仅当存在一系列移动操作使得start可以转换成end时, 返回True。

    在一个由 'L' , 'R' 和 'X' 三个字符组成的字符串(例如"RXXLRXRXL")中进行移动操作.一次移动操作指用一个"LX"替换一个"XL ...

  6. jQuery学习之二

    jQuery对象获取方法:var $cr=$("#cr"); //jQuery方法获取的是一个·对象数组. var cr=$cr[0] // var cr=$cr.get(0); ...

  7. 移动端H5混合开发,Touch触控,拖拽,长按, 滑屏 实现方案

    概述 近期由于产品快速原型开发的需要,不想用原声的方式开发App两端一起搞时间来不及,目前产品处于大量上feature的阶段,采用混合开发是最合适的选择,所以花了3天的时间研究怎么去实现移动端,拖拽, ...

  8. 爬虫----爬虫解析库Beautifulsoup模块

    一:介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮你 ...

  9. 使用介质设备安装 AIX 以通过 HMC 安装分区

    使用介质设备安装 AIX 以通过 HMC 安装分区 原文:https://www.ibm.com/support/knowledgecenter/zh/ssw_aix_72/com.ibm.aix.h ...

  10. STL 标准模板库

    <vector> 可变长的数组 Vector<int>v int是一个模板参数,这样传进来的都会是int V.push_back(a)将a传进v,且放在最后一个 V.clear ...