zoukankan      html  css  js  c++  java
  • Swift

     1 extension UIFont {
     2     class func fontName(fontName: String, size fontSize: CGFloat) -> UIFont {
     3         
     4         return UIFont(name: fontName, size: fontSize)!
     5     }
     6 }
     7 class ViewController: UIViewController {
     8 
     9     override func viewDidLoad() {
    10         super.viewDidLoad()
    11         // Do any additional setup after loading the view, typically from a nib.
    12         self.navigationItem.title = "Swift"
    13         
    14         ///1.常量
    15         let number: Int = 10
    16         print("the number is (number)")
    17         //1.1变量
    18         var string :String = "hello world!"
    19         print("(string.count)个字符")
    20         //1.2检查字符串是否有特定前缀/后缀:hasPrefix/hasSuffix
    21         if string.hasPrefix("hello") {
    22             print("hello首部")
    23         }
    24         if string.hasSuffix("!"){
    25             print("!在尾部")
    26         }
    27         //1.3空字符串
    28         string = "";
    29         if string.isEmpty {
    30             print("空字符串")
    31         }else{
    32             print("非空字符")
    33         }
    34         //1.4 元组
    35         let myproject = (one:"game",two:12345)
    36         print("myproject:(myproject)")
    37         
    38         //1.3 获取随机数
    39         let temp:Int = Int(arc4random()%100) + 1;
    40         print(temp)
    41         let temps : Int = Int(arc4random_uniform(100)) + 1;
    42         print(temps)
    43         
    44         /// 创建label
    45         let label = UILabel.init(frame: CGRect.init(x: 10, y: 15 + TOP_HEIGHT,  SCREEN_WIDTH - 20, height: 30))
    46         label.text = "the number is (number)"
    47         label.backgroundColor = RED_COLOR;
    48         label.textColor = GREEN_COLOR
    49         label.font = UIFont.fontName(fontName: "PingFangSC-Regular", size: 14)
    50         view.addSubview(label)
    51         var variableNumber = 42
    52         variableNumber = 24
    53         print("the variableNumber is (variableNumber)")
    54         
    55         
    56         
    57     }
  • 相关阅读:
    洛谷 P1045 【麦森数】快速幂
    洛谷 P4838 P哥破解密码 题解
    洛谷 P1609 最小回文数 题解
    洛谷 P4910 帕秋莉的手环 矩阵乘法+快速幂详解
    [SDOI2010]外星千足虫 题解 高斯消元+bitset简介
    UVA1386 【Cellular Automaton】题解
    JavaScript基础(.....持续待更)
    网页布局基础
    css浮动--float/clear通俗讲解(转载)
    css基础
  • 原文地址:https://www.cnblogs.com/edensyd/p/9405394.html
Copyright © 2011-2022 走看看