let与var的区别;var 在运行的时候可以多次赋值,let 只能赋值一次,再次赋值会报错
第一个label
let label1:UILabel = UILabel(frame:CGRect(x: 50,y: 50,width: 150,height: 80));
label1.text = "你好";
label1.transform = CGAffineTransformMakeRotation(0.2);
label1.textColor = UIColor.whiteColor();
label1.backgroundColor = UIColor.blackColor();
label1.layer.cornerRadius = 10;
label1.layer.borderColor = UIColor.purpleColor().CGColor;
label1.layer.borderWidth = 5;
label1.textAlignment = NSTextAlignment.Center;
label1.font = UIFont.boldSystemFontOfSize(50);
label1.shadowColor = UIColor.redColor();
label1.shadowOffset = CGSizeMake(15, 5);
self.view.addSubview(label1);
第二个label :显示html的文字,但是不知道是为什么 ,显示不了,希望各位大神指导一下:
let label2:UILabel = UILabel(frame:CGRect(x: 50,y: 250,width: 150,height: 80));
let html = "this is html <a href=\"http://www.baidu.com\">link</a>";
let data = html.dataUsingEncoding(NSUTF32StringEncoding, allowLossyConversion:false);
let atext = NSAttributedString(data:data!,options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType],documentAttributes:nil);
label2.multipleTouchEnabled = true;
label2.attributedText = atext;
[self.view.addSubview(label2)];
第三个label
let label3:UILabel = UILabel(frame: CGRect(x: 50, y: 600, width: 200, height: 80));
label3.backgroundColor = UIColor.purpleColor();
label3.textColor = UIColor.whiteColor();
label3.text = "在设置rootViewController之后,在这个control里的viewDidLoad方法里,添加相应的代码.设置了9个不同类型的UIButton";
label3.lineBreakMode = NSLineBreakMode.ByTruncatingTail; //文字过长时的省略方式
label3.numberOfLines = 10; // 使标签可以显示多行文字
label3.adjustsFontSizeToFitWidth = true; //文字大小自适应标签宽度
self.view.addSubview(label3);