iOS 快速创建控件UIView、UIButton、UILabel、UIImageView、UITextField

iOS开发中会经常用到UIView、UIButton、UILabel、UIImageView、UITextField这些控件,一行行创建就太麻烦浪费时间了,这里演示了快捷创建方法,只需下载后拖入项目,把.h文件放在pch中就可以快捷使用了,还附带一些小分类

demo由此下载



//创建UIView

UIView * view = [UIView viewWithFrame:CGRectMake((Screen_W-100)/2, 50, 100, 50) bgColor:[UIColor colorWithString:@"DCDCDC"]] ;

 [self.view addSubview:view];


//创建UIButton

UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom frame:CGRectMake((Screen_W-100)/2, 150, 100, 50) image:@"tips_icon" fontSize:12 titleColor:[UIColor colorWithString:@"FF4500"] title:@"UIButton"];

 //设置文字、图片位置间距

 [button layoutButtonWithEdgeInsetsStyle:LZHButtonEdgeInsetsStyleRight imageTitleSpace:5];

 button.backgroundColor= [UIColor colorWithString:@"DCDCDC"] ;

 [self.view addSubview:button];


//创建UILabel

UILabel * label = [UILabel lableWithFrame:CGRectMake((Screen_W-100)/2, 250, 100, 50) text:@"UILabel" textColor:[UIColor colorWithString:@"4169E1"] textFont:12 textAlignment:1 lines:0];

label.backgroundColor= [UIColor colorWithString:@"DCDCDC"] ;

[self.view addSubview:label];


//创建UIImageView

UIImageView* imageView = [UIImageViewimageViewWithFrame:CGRectMake((Screen_W-40)/2,350,40,40)imageName:@"tips_icon"];

imageView.backgroundColor= [UIColor colorWithString:@"DCDCDC"] ;

[self.view addSubview:imageView];


//创建UITextField

UITextField * textField = [UITextField textFieldWithFrame:CGRectMake((Screen_W-100)/2, 450, 100, 50) textColor:[UIColor colorWithString:@"000000"] textFont:[UIFont systemFontOfSize:12 weight:UIFontWeightMedium] textAlignment:0 tintColor:[UIColor colorWithString:@"000000"] keyboardType:UIKeyboardTypeDefault clearButtonMode:UITextFieldViewModeAlways returnKeyType:UIReturnKeyDefault placeholderText:@"占位文字" placeholderFont:[UIFont systemFontOfSize:12] placeholderColor:[UIColor colorWithString:@"808080"]];

textField.layer.borderWidth=1;

textField.layer.borderColor= [UIColor colorWithString:@"000000"alpha:0.5].CGColor;

textField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 10.f, 0.f)];

textField.leftViewMode = UITextFieldViewModeAlways;

textField.backgroundColor= [UIColor colorWithString:@"DCDCDC"] ;

[self.view addSubview:textField];

你可能感兴趣的:(iOS 快速创建控件UIView、UIButton、UILabel、UIImageView、UITextField)