UILable是iPhone界面最基本的控件,主要用来显示文本信息。
常用属性和方法有:
创建UILabel
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 200, realSize.height)];
label.backgroundColor = [UIColor grayColor];
设置显示的内容
label.text = text;
设置字体颜色
label.textColor = [UIColor orangeColor];
设置字体和字号
label.font = [UIFont systemFontOfSize:20];
设置多行显示
label.numberOfLines = 0;
设置换行的方式
label.lineBreakMode = NSLineBreakByCharWrapping;
设置对齐方式
label.textAlignment = NSTextAlignmentLeft;
添加到界面上
[self.view addSubview:label];
设置阴影 UIView
label.layer.shadowColor = [UIColor blackColor].CGColor;
label.layer.shadowOffset = CGSizeMake(-20, 5);
label.layer.shadowRadius = 5;
label.layer.shadowOpacity = 1;
添加边框
titleLabel.layer.borderColor = [[UIColor grayColor] CGColor];//边框颜色
titleLabel.layer.borderWidth = 2;//边框的宽度