ios控件 UILabel

时间:2023-03-10 07:16:18
ios控件 UILabel
UILabel 的作用是显示文本
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 40)]; label.text = @"代佳宏";//创建文本的内容 nil
label.textColor = [UIColor redColor];//设置文本颜色
label.font = [UIFont systemFontOfSize:23];//设置字体大小

label.shadowColor = [UIColor blueColor];//设置阴影颜色

label.shadowOffset = CGSizeMake(2, 2);//设置阴影偏移量

[self.view addSubview:label];//显示文本

NSTextAlignment label.textAlignment = NSTextAlignmentCenter; //文本居中
label.lineBreakMode = NSLineBreakByCharWrapping;
//文本打断方式

label.numberOfLines = 3;
//文本行数  为0时则为任意行

label.userInteractionEnabled = YES; //打开UIBlable交互

[label sizeToFit];//自动根据文本大小调整UIBlabel