[Xcode 实际操作]四、常用控件-(3)UILabel文本标签的使用

目录:[Swift]Xcode实际操作

本文将演示标签控件的基础用法,

在项目导航区,打开视图控制器的代码文件【ViewController.swift】

 1 import UIKit
 2 
 3 class ViewController: UIViewController {
 4 
 5     override func viewDidLoad() {
 6         super.viewDidLoad()
 7         // Do any additional setup after loading the view, typically from a nib.
 8         //创建一个位置在(20,100),尺寸为(280,80)的显示区域
 9         let rect = CGRect(x: 20, y: 100, width: 280, height: 80)
10         //设置标签对象的显示区域
11         let label = UILabel(frame: rect)
12         //设置标签对象在默认情况下,显示的文字内容
13         label.text = "Hello, Xcode and Swift!"
14         
15         //创建一个指定大小的字体对象
16         let font = UIFont(name: "Arial", size: 24)
17         //设置标签对象文字的字体和大小
18         label.font = font
19         
20         //设置标签文字的字体颜色为浅灰色
21         label.shadowColor = UIColor.lightGray
22         //设置标签文字的阴影,在横向和纵向上的偏移距离
23         label.shadowOffset = CGSize(width: 2, height: 2)
24         
25         //设置标签文字的对齐方式为右对齐
26         label.textAlignment = NSTextAlignment.right
27         //设置标签文字的颜色为紫色
28         label.textColor = UIColor.purple
29         //设置标签的背景颜色为黄色
30         label.backgroundColor = UIColor.yellow
31         
32         //将标签对象,添加到当前视图控制器的根视图
33         self.view.addSubview(label)
34     }
35 
36     override func didReceiveMemoryWarning() {
37         super.didReceiveMemoryWarning()
38         // Dispose of any resources that can be recreated.
39     }
40 }

 

转载于:https://www.cnblogs.com/strengthen/p/10014715.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值