iOS 快速創(chuàng)建控件UIView、UIButton、UILabel、UIImageView、UITextField

iOS開發(fā)中會經(jīng)常用到UIView、UIButton、UILabel、UIImageView、UITextField這些控件,一行行創(chuàng)建就太麻煩浪費時間了,這里演示了快捷創(chuàng)建方法,只需下載后拖入項目,把.h文件放在pch中就可以快捷使用了,還附帶一些小分類

demo由此下載



//創(chuàng)建UIView

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

?[self.view addSubview:view];


//創(chuàng)建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"];

?//設(shè)置文字、圖片位置間距

?[button layoutButtonWithEdgeInsetsStyle:LZHButtonEdgeInsetsStyleRight imageTitleSpace:5];

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

?[self.view addSubview:button];


//創(chuàng)建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];


//創(chuàng)建UIImageView

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

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

[self.view addSubview:imageView];


//創(chuàng)建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];

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容