#import <Foundation/Foundation.h>
@interface ZCControl : NSObject
#pragma mark --创建View
+(UIView*)createView:(CGRect)frame;
#pragma mark --创建Label
+(UILabel*)createLabelWithFrame:(CGRect)frame Text:(NSString*)text Font:(int)font;
#pragma mark --创建下划线Label
+(UILabel*)createBottomLineLabelWithFrame:(CGRect)frame Text:(NSString*)text Font:(int)font;
#pragma mark --创建button
+(UIButton*)createButtonWithFrame:(CGRect)frame Font:(int)font Text:(NSString*)text ImageName:(NSString*)imageName bgImageName:(NSString*)bgImageName Target:(id)target Method:(SEL)Method;
#pragma mark --创建imageView
+(UIImageView*)createImageViewWithFrame:(CGRect)frame ImageName:(NSString*)imageName;
#pragma mark --创建UITextField
+(UITextField*)createTextFieldWithFrame:(CGRect)frame placeholder:(NSString*)placeholder passWord:(BOOL)YESorNO leftImageView:(UIImageView*)imageView rightImageView:(UIImageView*)rightImageView Font:(float)font backgRoundImageName:(NSString*)imageName;
#pragma mark --创建UITextView
+(UITextView*)createTextViewWithFrame:(CGRect)frame scrollEnabled:(BOOL)scrollEnabled editable:(BOOL)editable Font:(float)font;
#pragma mark 创建UIPageControl
+(UIPageControl*)makePageControlWithFram:(CGRect)frame;
#pragma mark 创建UISlider
+(UISlider*)makeSliderWithFrame:(CGRect)rect AndImage:(UIImage*)image;
@end
#import "ZCControl.h"
@implementation ZCControl
#pragma mark --创建View
+(UIView*)createView:(CGRect)frame
{
UIView * view = [[UIView alloc]initWithFrame:frame];
return view;
}
#pragma mark --创建Label
+(UILabel*)createLabelWithFrame:(CGRect)frame Text:(NSString*)text Font:(int)font
{
UILabel * label = [[UILabel alloc]initWithFrame:frame];
label.text = text;
label.font = [UIFont systemFontOfSize:font];
//label.adjustsFontSizeToFitWidth = YES;
return label;
}
#pragma mark --创建下划线Label
+(UILabel*)createBottomLineLabelWithFrame:(CGRect)frame Text:(NSString*)text Font:(int)font
{
UILabel * label = [[UILabel alloc]initWithFrame:frame];
label.font = [UIFont systemFontOfSize:font];
//下划线
NSMutableAttributedString * attribtStr = [[NSMutableAttributedString alloc] initWithString:text];
NSRange contentRange = {0, [attribtStr length]};
[attribtStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
//赋值
label.attributedText = attribtStr;
//label.adjustsFontSizeToFitWidth = YES;
return label;
}
#pragma mark --创建button
+(UIButton*)createButtonWithFrame:(CGRect)frame Font:(int)font Text:(NSString*)text ImageName:(NSString*)imageName bgImageName:(NSString*)bgImageName Target:(id)target Method:(SEL)Method
{
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
//button.fy_acceptEventInterval = 0.5;按钮响应间隔
button.frame = frame;
if (![PublicFunction isBlankString:imageName]) {
[button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
}
if (![PublicFunction isBlankString:bgImageName]) {
[button setBackgroundImage:[UIImage imageNamed:bgImageName] forState:UIControlStateNormal];
}
if (text) {
[button setTitle:text forState:UIControlStateNormal];
}
button.titleLabel.font = [UIFont systemFontOfSize:font];
[button addTarget:target action:Method forControlEvents:UIControlEventTouchUpInside];
//禁止高亮
[button setAdjustsImageWhenHighlighted:NO];
return button;
}
#pragma mark --创建imageView
+(UIImageView*)createImageViewWithFrame:(CGRect)frame ImageName:(NSString*)imageName
{
UIImageView * imageView = [[UIImageView alloc]initWithFrame:frame];
if (![PublicFunction isBlankString:imageName]) {
imageView.image = [UIImage imageNamed:imageName];
}
imageView.userInteractionEnabled = YES;
return imageView;
}
#pragma mark --创建UITextField
+(UITextField*)createTextFieldWithFrame:(CGRect)frame placeholder:(NSString*)placeholder passWord:(BOOL)YESorNO leftImageView:(UIImageView*)imageView rightImageView:(UIImageView*)rightImageView Font:(float)font backgRoundImageName:(NSString*)imageName
{
UITextField * textField = [[UITextField alloc]initWithFrame:frame];
//灰色提示框
textField.placeholder = placeholder;
//文字对齐方式
textField.textAlignment = NSTextAlignmentLeft;
textField.secureTextEntry = YESorNO;
//边框
textField.borderStyle = UITextBorderStyleRoundedRect;
//键盘类型
textField.keyboardType = UIKeyboardTypeEmailAddress;
//关闭首字母大写
textField.autocapitalizationType = NO;
//清除按钮
textField.clearButtonMode = YES;
//左图片
textField.leftView = imageView;
textField.leftViewMode = UITextFieldViewModeAlways;
//右图片
textField.rightView = rightImageView;
//编辑状态下一直存在
textField.rightViewMode = UITextFieldViewModeWhileEditing;
//字体
textField.font = [UIFont systemFontOfSize:font];
if (imageName) {
textField.background = [UIImage imageNamed:imageName];
}
return textField ;
}
#pragma mark --创建UITextView
+(UITextView*)createTextViewWithFrame:(CGRect)frame scrollEnabled:(BOOL)scrollEnabled editable:(BOOL)editable Font:(float)font
{
UITextView * textView = [[UITextView alloc]initWithFrame:frame];
//文字对齐方式
textView.textAlignment = NSTextAlignmentLeft;
//当文字超过视图的边框时是否允许滑动,默认为“YES”
textView.scrollEnabled=scrollEnabled;
//是否允许编辑内容,默认为“YES”
textView.editable=editable;
//字体
textView.font=[UIFont systemFontOfSize:font];
//边框颜色
textView.layer.borderColor = [[UIColor colorWithRed:215.0/255.0 green:215.0/255.0 blue:215.0/255.0 alpha:1.0]CGColor];
//边框宽度
textView.layer.borderWidth = 0.5;
//边框圆角
textView.layer.masksToBounds = YES;
textView.layer.cornerRadius = 5;
return textView;
}
#pragma mark 创建UIPageControl
+(UIPageControl*)makePageControlWithFram:(CGRect)frame
{
UIPageControl * pageControl = [[UIPageControl alloc] initWithFrame:frame];
pageControl.numberOfPages = 2;
pageControl.currentPage = 0;
return pageControl;
}
#pragma mark 创建UISlider
+(UISlider*)makeSliderWithFrame:(CGRect)rect AndImage:(UIImage*)image
{
UISlider * slider = [[UISlider alloc]initWithFrame:rect];
slider.minimumValue = 0;
slider.maximumValue = 1;
[slider setThumbImage:[UIImage imageNamed:@"qiu"] forState:UIControlStateNormal];
slider.maximumTrackTintColor = [UIColor grayColor];
slider.minimumTrackTintColor = [UIColor yellowColor];
slider.continuous = YES;
slider.enabled = YES;
return slider ;
}
@end
网友评论