UIView
//视图使用UIVIEW类来表示,UIVIEW是系统已提供好的类,可以拿来直接使用,UIVIEW在UIKIt框架里面.
//第一步 创建视图(此刻不会显示)
UIView *aView=[[UIView alloc]initWithFrame:CGRectMake(40, 70, 240, 240)];
//第二部 添加到window上进行显示
[self.window addSubview:aView];
//第三步 视图进行相关设置(UIVIEW 默认是 透明色也就是clearColor)
[aView setBackgroundColor:[UIColor blueColor]];
aView.backgroundColor=[UIColor clearColor];
aView.layer.borderWidth=5;
aView.layer.cornerRadius=120;
//第四部 内存管理(释放)
[aView release];
/*学习要讲究方法,流程性的东西最有指导性作用的.上面列出 了所有MVC中V使用流程.记得流程胜过背代码*/
//MVC里的V一般不提供便利构造器方法,只提供初始化方法.
//子视图以父视图坐标为原点
//同为子视图后加在前面(子视图加在父视图前面)
UIView * userView=[[UIView alloc]initWithFrame:CGRectMake(20, 50, 50, 30)];
userView.backgroundColor=[UIColor clearColor];
userView.layer.borderWidth=1;
userView.layer.cornerRadius=10;
[aView addSubview:userView];
[userView release];
UILable
UILabel用于显示文本的控件 集成于uiview.相比uiview ,uilable类添加了空间的外观,提供了显示文字的功能
使用UI步骤
1.创建控件(alloc 初始化)
注意:只要是空间,都需要设置frame 2.优先使用本类的初始化方法,如果没有,使用父类继承过初始化方法,以此类推.
UILabel *useNameLable=[[UILabel alloc]initWithFrame:CGRectMake(30, 230, 70, 25)];
// 2.对控件进行设置(枚举值 自己试试)
useNameLable.backgroundColor=[UIColor clearColor];
// useNameLable.font=[UIFont italicSystemFontOfSize:20];
useNameLable.layer.borderWidth=1;
useNameLable.layer.cornerRadius=4;
useNameLable.text=@" 用户名:";// _useNameText=[[UITextField alloc]initWithFrame:CGRectMake(120, 230, 130, 25)];
// 3.添加到父视图
[loginContainerView addSubview:useNameLable];
// 4.释放
[useNameLable release];
UITextFild
//定义成属性
// _useNameText=[[UITextField alloc]initWithFrame:CGRectMake(120, 230, 130, 25)];
// _useNameText.backgroundColor=[UIColor clearColor];
// [loginContainerView addSubview:_useNameText];
// _useNameText.layer.borderWidth=1;
// _useNameText.layer.cornerRadius=4;
// //指定输入框占位
// _useNameText.placeholder=@"请输入用户名";
// //输入为大写或首字母大写等等
// _useNameText.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;
// //是否自动纠正
// _useNameText.autocorrectionType=UITextAutocorrectionTypeYes;
// //useNameText.borderStyle=[UITextBorderStyleRoundedRect];
// //改变样式
// _useNameText.borderStyle=UITextBorderStyleRoundedRect;
// _useNameText.delegate=self;
//定义一个passWordText属性
// _passWordText=[[UITextField alloc]initWithFrame:CGRectMake(120, 280, 130, 25)];
// _passWordText.backgroundColor=[UIColor clearColor];
// [loginContainerView addSubview:_passWordText];
// _passWordText.layer.borderWidth=1;设置边框
// _passWordText.layer.cornerRadius=4;//设置圆角
// _passWordText.adjustsFontSizeToFitWidth=10;
// _passWordText.placeholder=@"请输入密码";
// _passWordText.secureTextEntry=YES;//设置输入的文字显示为圆点,
// _passWordText.delegate=self;//代理
UIButton
初始化
// UIButton * confirmButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
// confirmButton.frame=CGRectMake(30,350 , 50, 20);
设置属性
// confirmButton.backgroundColor=[UIColor clearColor];
// [loginContainerView addSubview:confirmButton];
confirmButton.backgroundColor=[UIColor orangeColor];
// [confirmButton setTitle:@"登陆" forState:UIControlStateNormal];
// confirmButton.layer.borderWidth=1;
// confirmButton.layer.cornerRadius=4;
[confirmButton setTitle:@"login" forState:UIControlStateHighlighted];//添加事件
// [confirmButton addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
下面是写了一些组合控件
UIlable和UITextField组合
@interface CustomTextField : UIView <UITextFieldDelegate>
@property(nonatomic ,strong)UILabel *descriptionlable;
@property(nonatomic,strong)UITextField *textField;
-(id)initWithFrame:(CGRect)frame description:(NSString *)description textField:(NSString *)textField;
@end
.m文件
-(id)initWithFrame:(CGRect)frame description:(NSString *)description textField:(NSString *)textField;
{
self = [super initWithFrame:frame];
if (self) {
CGFloat width=frame.size.width;
CGFloat height=frame.size.height;
_descriptionlable=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, width/3, height)];
_descriptionlable.textAlignment=NSTextAlignmentRight;
_descriptionlable.backgroundColor=[UIColor grayColor];
_descriptionlable.text=description;
_descriptionlable.layer.borderWidth=1;
_descriptionlable.layer.cornerRadius=5;
_descriptionlable.alpha=0.6;
[self addSubview:_descriptionlable];
_textField=[[UITextField alloc]initWithFrame:CGRectMake(width/3, 0, width-width/3, height)];
_textField.borderStyle=UITextBorderStyleRoundedRect;
_textField.text=textField;
_textField.alpha=0.6;
_textField.backgroundColor=[UIColor grayColor];
_textField.layer.borderWidth=1;
_textField.layer.cornerRadius=5;
_textField.delegate=self;
[self addSubview:_textField];
// Initialization code
}
return self;
}
UIButoon分类
@interface UIButton (CategoryButton)
+ (UIButton *)roundRectButtonWithFrame:(CGRect)frame title:(NSString *)title target:(id)target action:(SEL)action;
+ (UIButton *)buttonWithType:(UIButtonType)type frame:(CGRect)frame title:(NSString *)title target:(id)target action:(SEL)action;
@end
#import "UIButton+CategoryButton.h"
@implementation UIButton (CategoryButton)
+ (UIButton *)roundRectButtonWithFrame:(CGRect)frame title:(NSString *)title target:(id)target action:(SEL)action
{
return [UIButton buttonWithType:UIButtonTypeRoundedRect frame:frame title:title target:target action:action];
}
+ (UIButton *)buttonWithType:(UIButtonType)type frame:(CGRect)frame title:(NSString *)title target:(id)target action:(SEL)action
{
UIButton *button = [UIButton buttonWithType:type];
button.frame = frame;
[button setTitle:title forState:UIControlStateNormal];
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
button.layer.borderWidth=1;
button.layer.contentsScale=1;
return button;
}
@end