UI初级中的控件是UI学习的最基本的应用,下面是一些最基础的控件的应用

UILabel

#pragmamark-UILabel

-(void)_initLabel

{

UILabel*textLable=[[UILabelalloc]initWithFrame:CGRectMake(10,30,150,250)];

textLable.backgroundColor=[UIColorgrayColor];

//设置文本内容

textLable.text=@"goodmorninghehehehehegoodmorninghehehehehe";

//设置字体,systemFont使用系统的字体,大小10

textLable.font=[UIFontsystemFontOfSize:16];

//设置粗体

textLable.font=[UIFontboldSystemFontOfSize:16];

//字体类UIFont

NSArray*familyNames=[UIFontfamilyNames];

NSLog(@"familyNamesis%@",familyNames);

textLable.font=[UIFontfontWithName:@"ZapfDingbats"size:16];

//设置字体颜色

textLable.textColor=[UIColororangeColor];

//设置文本对齐方式

textLable.textAlignment=NSTextAlignmentCenter;

//设置当前的显示行数,默认是1行,如果设为0,是自动换行

textLable.numberOfLines=0;

//自动根据文本调整宽度和高度

[textLablesizeToFit];

//NSLog(@"textLabelis%@",textLable);

[self.windowaddSubview:textLable];

}

UIButton

#pragmamark-UIButton

-(void)_initButton

{

UIButton*button=[UIButtonbuttonWithType:UIButtonTypeCustom];

button.frame=CGRectMake(10,180,90,44);

button.backgroundColor=[UIColorgreenColor];

//设置显示标题,标题总是需要跟状态绑定到一起的

//button.titleLabel.text=@"hehe";//错误,不能这样设置title

/*

typedefNS_OPTIONS(NSUInteger,UIControlState){

UIControlStateNormal=0,

UIControlStateHighlighted=1<<0,//usedwhenUIControlisHighlightedisset

UIControlStateDisabled=1<<1,

UIControlStateSelected=1<<2,//flagusablebyapp(seebelow)

UIControlStateApplication=0x00FF0000,//additionalflagsavailableforapplicationuse

UIControlStateReserved=0xFF000000//flagsreservedforinternalframeworkuse

};

*/

[buttonsetTitle:@"hehe"forState:UIControlStateNormal];

//设置高亮状态下的title

//[buttonsetTitle:@"haha"forState:UIControlStateHighlighted];

//设置选中状态下的title

//[buttonsetTitle:@"hihi"forState:UIControlStateSelected];

//设置按钮是否选中

//button.selected=true;

//设置标题的字体

button.titleLabel.font=[UIFontboldSystemFontOfSize:20];

//设置标题的颜色

[buttonsetTitleColor:[UIColorredColor]forState:UIControlStateNormal];

//[buttonsetTitleColor:[UIColoryellowColor]forState:UIControlStateSelected];