UI初级中的控件是UI学习的最基本的应用,下面是一些最基础的控件的应用
#pragma mark -UILabel
- (void)_initLabel
{
UILabel *textLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 150, 250)];
textLable.backgroundColor = [UIColor grayColor];
//设置文本内容
textLable.text = @"good morning hehehehehe good morning hehehehehe";
//设置字体, systemFont使用系统的字体,大小10
textLable.font = [UIFont systemFontOfSize:16];
//设置粗体
textLable.font = [UIFont boldSystemFontOfSize:16];
//字体类 UIFont
NSArray *familyNames = [UIFont familyNames];
NSLog(@"familyNames is %@", familyNames);
textLable.font = [UIFont fontWithName:@"Zapf Dingbats" size:16];
//设置字体颜色
textLable.textColor = [UIColor orangeColor];
//设置文本对齐方式
textLable.textAlignment = NSTextAlignmentCenter;
//设置当前的显示行数,默认是1行, 如果设为0,是自动换行
textLable.numberOfLines = 0;
//自动根据文本调整宽度和高度
[textLable sizeToFit];
// NSLog(@"textLabel is %@", textLable);
[self.window addSubview:textLable];
}
#pragma mark -UIButton
- (void)_initButton
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(10, 180, 90, 44);
button.backgroundColor = [UIColor greenColor];
//设置显示标题, 标题总是需要跟状态绑定到一起的
// button.titleLabel.text = @"hehe"; //错误,不能这样设置title
/*
typedef NS_OPTIONS(NSUInteger, UIControlState) {
UIControlStateNormal = 0,
UIControlStateHighlighted = 1 << 0, // used when UIControl isHighlighted is set
UIControlStateDisabled = 1 << 1,
UIControlStateSelected = 1 << 2, // flag usable by app (see below)
UIControlStateApplication = 0x00FF0000, // additional flags available for application use
UIControlStateReserved = 0xFF000000 // flags reserved for internal framework use
};
*/
[button setTitle:@"hehe" forState:UIControlStateNormal];
//设置高亮状态下的title
// [button setTitle:@"haha" forState:UIControlStateHighlighted];
//设置选中状态下的title
// [button setTitle:@"hihi" forState:UIControlStateSelected];
//设置按钮是否选中
// button.selected = true;
//设置标题的字体
button.titleLabel.font = [UIFont boldSystemFontOfSize:20];
//设置标题的颜色
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
// [button setTitleColor:[UIColor yellowColor] forState:UIControlStateSelected];
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。