类方法创建控件
来源:互联网 发布:linux执行器 编辑:程序博客网 时间:2024/06/07 02:41
#pragma mark - 获取一个字符串的Size
+ (CGSize )getSizeWithString:(NSString *)str WithSize:(CGSize )allowSize font:(NSInteger )font {
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStylealloc]init];
paragraphStyle.lineBreakMode =NSLineBreakByWordWrapping;
NSDictionary *attributes =@{NSFontAttributeName:[UIFontsystemFontOfSize:font],
NSParagraphStyleAttributeName:paragraphStyle.copy};
CGSize size = [strboundingRectWithSize:allowSize
options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading
attributes:attributescontext:nil].size;
returnCGSizeMake(size.width,ceilf(size.height));
}
#pragma mark - 创建一个Button
+ (UIButton *)creatButonWithType:(UIButtonType )type
Frame:(CGRect )frame
title:(NSString *)title
titleColor:(UIColor *)titleColor
image:(UIImage *)image font:(NSInteger )font {
UIButton *button = [UIButtonbuttonWithType:type];
button.frame = frame;
[button setTitle:titleforState:UIControlStateNormal];
[button setTitleColor:titleColorforState:UIControlStateNormal];
[button setImage:imageforState:UIControlStateNormal];
button.titleLabel.font = [UIFontsystemFontOfSize:font];
return button;
}
#pragma mark -创建一个Label
+ (UILabel *)creatLabelWithFrame:(CGRect )frame
title:(NSString *)title
titleColor:(UIColor *)titleColor
font:(NSInteger )font {
UILabel *label = [[UILabelalloc] initWithFrame:frame];
label.text = title;
label.font = [UIFontsystemFontOfSize:font];
label.textColor = titleColor;
return label;
}
#pragma mark - textField
+(UITextField *)createTextFielfFrame:(CGRect)frame font:(UIFont *)font placeholder:(NSString *)placeholder{
UITextField *textField = [[UITextFieldalloc]initWithFrame:frame];
textField.font = font;
textField.textColor = [UIColorgrayColor];
textField.borderStyle = UITextBorderStyleNone;
textField.placeholder = placeholder;
return textField;
}
#pragma mark - imageView
+(UIImageView *)createImageViewFrame:(CGRect)frame imageName:(NSString *)imageName color:(UIColor *)color{
UIImageView *imageView=[[UIImageViewalloc]initWithFrame:frame];
if (imageName){
imageView.image=[UIImageimageNamed:imageName];
}
if (color){
imageView.backgroundColor=color;
}
return imageView;
}
#pragma mark - button
+(UIButton *)createButtonFrame:(CGRect)frame backImageName:(NSString *)imageName title:(NSString *)title titleColor:(UIColor *)color font:(UIFont *)font target:(id)target action:(SEL)action{
UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeCustom];
btn.frame = frame;
if (imageName){
[btn setBackgroundImage:[UIImageimageNamed:imageName] forState:UIControlStateNormal];
}
if (font){
btn.titleLabel.font = font;
}
if (title){
[btn setTitle:titleforState:UIControlStateNormal];
}
if (color){
[btn setTitleColor:colorforState:UIControlStateNormal];
}
if (target&&action){
[btn addTarget:targetaction:action forControlEvents:UIControlEventTouchUpInside];
}
return btn;
}
- 类方法创建控件
- swift中类方法创建button等等其他控件
- 总结下动态创建控件的方法
- 使用js动态创建控件的方法
- 创建超链接静态控件(概述方法)
- 利用金山创建网页控件方法
- 简单的自定义控件创建方法
- 简单的自定义控件创建方法
- iOS---各种控件的创建方法和部分调用方法
- iOS---各种控件的创建方法和部分调用方法
- view类某些控件创建时候系统自动帮助我们调用的某些方法
- 创建控件
- 创建控件
- 自定义WEB控件的步聚及创建方法
- javascript动态创建控件的3种方法
- 使用ALT创建activex控件时标记安全方法
- JAVA高级:js动态创建控件的方法
- 添加动态创建控件的消息的简便方法
- 为什么静态成员、静态方法中不能用this和super关键字
- 信息检索模型与评估
- MySQL数据类型和常用字段属性总结
- 区块链技术是什么鬼
- 关于中文字符串乱码解决方案
- 类方法创建控件
- keepalived+redis实现主备
- JDK1.7的新特性
- Android 下 RxJava 详解,长篇巨作,由浅入深。
- 《Qt5学习笔记1》安装Qt5并配置环境变量
- RobotFramework+SeleniumLibrary 安装及简单使用方法使用(未完成)
- lua 排序
- 天堂里的游戏-(2)51Nod
- 安卓高德地图的使用