美文网首页
Swift Tips(持续更新)

Swift Tips(持续更新)

作者: 上帝也是码农 | 来源:发表于2016-10-15 16:36 被阅读6次

    1、NSMutableAttributedString to String

    var attributedString = NSMutableAttributedString(string: "hello, world!")
    var str = attributedString.string
    

    2、swift中的交换元素
    使用swift中的Tuple(多元组)

    var a = 10
    var b = 20
    (a,b) = (b,a)
    print(a,b)//a = 20,b = 10
    

    3、判断字符串相等

    var str = "hello, world!"
    if str == "hello, world!" {
        print("equal")
    }
    

    4、获取字符串长度

    var str = "hello, world!"
    print(str.characters.count)
    

    5、transform

    self.textField.transform = CGAffineTransform.init(translationX: 0, y: 100)
    

    6、character to string

    let greeting = "Guten Tag!"
    let index = greeting.index(greeting.startIndex, offsetBy: 0)
    var myStr:String = String(greeting[index])
    

    7、获得键盘的高度

    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
        let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)
        // ...
    }
    

    相关文章

      网友评论

          本文标题:Swift Tips(持续更新)

          本文链接:https://www.haomeiwen.com/subject/nxxoyttx.html