zoukankan      html  css  js  c++  java
  • [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,  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( 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 }
  • 相关阅读:
    EasyUI:combotree(树形下拉框)复选框选中父节点(子节点的状态也全部选中)输入框中只显示父节点的文本值
    js表单插件
    前端模块化入门
    前端模板引擎
    量化策略研究员
    量化策略研究员
    C++ 纯虚函数接口,标准 C 导出 DLL 函数的用法
    一月5日
    一月5日
    一月5日
  • 原文地址:https://www.cnblogs.com/strengthen/p/10014715.html
Copyright © 2011-2022 走看看