iOS 快速创建控件
来源:互联网 发布:分类信息网群发软件 编辑:程序博客网 时间:2024/06/03 15:40
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface QuickBuild : NSObject
/** 创建UILabel */
+ (UILabel *)quickBuildLableWithFrame:(CGRect)frame
text:(NSString *)text
color:(UIColor *)color
font:(UIFont *)font
textAlignment:(NSTextAlignment)textAlignment;
/** 创建UITextField */
+ (UITextField *)quickBuildTextFieldWithFrame:(CGRect)frame
placeholder:(NSString *)placeholder
color:(UIColor *)color
font:(UIFont *)font
secureTextEntry:(BOOL)secureTextEntry
delegate:(id)delegate;
/** 创建UITextView */
+ (UITextView *)quickBuildTextViewWithFrame:(CGRect)frame
text:(NSString *)text
color:(UIColor *)color
font:(UIFont *)font
textAlignment:(NSTextAlignment)textAlignment;
/** 创建UIButton */
+ (UIButton *)quickBuildButtonWithFrame:(CGRect)frame
title:(NSString *)title
color:(UIColor *)color
font:(UIFont *)font
backgroundImage:(UIImage *)backgroundImage
target:(id)target
action:(SEL)action;
/** 创建图片控件 */
+ (UIImageView*) quickBuildImageViewWithFrame:(CGRect)frame
image:(UIImage*)image;
/** 创建带颜色图片 */
+ (UIImage*) quickBuildimageWithColor:(UIColor*)color;
@end
@implementation QuickBuild
+ (UILabel *)quickBuildLableWithFrame:(CGRect)frame text:(NSString *)text color:(UIColor *)color font:(UIFont *)font textAlignment:(NSTextAlignment)textAlignment {
UILabel *label = [[UILabelalloc]initWithFrame:frame];
label.text = text;
label.textColor = color;
label.font = font;
label.textAlignment = textAlignment;
label.backgroundColor = [UIColorclearColor];
return label;
}
+ (UITextField *)quickBuildTextFieldWithFrame:(CGRect)frame placeholder:(NSString *)placeholder color:(UIColor *)color font:(UIFont *)font secureTextEntry:(BOOL)secureTextEntry delegate:(id)delegate {
UITextField *textField = [[UITextFieldalloc]initWithFrame:frame];
textField.placeholder = placeholder;
textField.textColor = color;
textField.font = font;
textField.secureTextEntry = secureTextEntry;
textField.delegate = delegate;
return textField;
}
+ (UITextView *)quickBuildTextViewWithFrame:(CGRect)frame text:(NSString *)text color:(UIColor *)color font:(UIFont *)font textAlignment:(NSTextAlignment)textAlignment {
UITextView *textView = [[UITextViewalloc]initWithFrame:frame];
textView.text = text;
textView.textColor = color;
textView.textAlignment = textAlignment;
textView.backgroundColor = [UIColorclearColor];
textView.editable = NO;
textView.scrollEnabled = NO;
textView.dataDetectorTypes =UIDataDetectorTypeLink;
return textView;
}
+ (UIButton *)quickBuildButtonWithFrame:(CGRect)frame title:(NSString *)title color:(UIColor *)color font:(UIFont *)font backgroundImage:(UIImage *)backgroundImage target:(id)target action:(SEL)action {
UIButton *btn = [[UIButtonalloc]initWithFrame:frame];
[btn setTitle:titleforState:UIControlStateNormal];
[btn setTitleColor:colorforState:UIControlStateNormal];
[btn.titleLabelsetFont:font];
[btn setBackgroundImage:backgroundImageforState:UIControlStateNormal];
[btn addTarget:targetaction:actionforControlEvents:UIControlEventTouchUpInside];
return btn;
}
+ (UIImageView*) quickBuildImageViewWithFrame:(CGRect)frame image:(UIImage*)image {
UIImageView *imgView = [[UIImageViewalloc]initWithFrame:frame];
imgView.contentMode =UIViewContentModeScaleAspectFill;
imgView.image = image;
return imgView;
}
+ (UIImage*) quickBuildimageWithColor:(UIColor*)color {
CGSize imageSize = CGSizeMake(1, 1);
UIGraphicsBeginImageContextWithOptions(imageSize,0, [UIScreenmainScreen].scale);
[color set];
UIRectFill(CGRectMake(0,0, imageSize.width, imageSize.height));
UIImage *img =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
@end
// 使用方法
UILabel *label = [QuickBuildquickBuildLableWithFrame:CGRectMake(0,60, 200, 100)text:@"123dsfsfsfdsfsfsfsfsfsfdsfsdfsd"color:[UIColorwhiteColor] font:[UIFontsystemFontOfSize:30]textAlignment:(NSTextAlignmentCenter)];
[self.viewaddSubview:label];
- iOS 快速创建控件
- iOS 快速创建常用控件
- ios创建一个控件
- command+d快速创建控件
- iOS开发系列之常用自定义控件开发集—继承UIButton控件代码快速创建按钮开发
- iOS快速创建单例
- IOS导航,tabBar快速创建
- iOS 常用控件的创建
- 【iOS】快速集成轮播控件
- iOS中使用@方法快速创建对象
- 快速创建IOS里的所有视图
- iOS OC 快速创建 数组 字典
- iOS XML解析快速创建model
- ios快速创建一个app框架
- iOS中常见控件的创建
- IOS-关于创建控件小技巧
- IOS创建控件的注意点
- IOS开发笔记26-代码创建控件
- HDU6198 number number number
- #CCF准备一年日常刷题#201312-2 ISBN号码
- 了解dom:DOM全称为The Document Object Model
- 笔记-拿向量存索引的树
- Jenkins Mail 设置
- iOS 快速创建控件
- MATLAB数组处理相关命令
- go语言电子书
- 小程序wx.showToast(OBJECT) image参数值
- Tensorflow中常用函数记载
- 5分钟让你了解 ZooKeeper 的原理
- NYOJ42 一笔画问题
- CentOS6.5环境部署Hadoop2.8.1集群(HA)
- JDBC