美文网首页
swift实践笔记

swift实践笔记

作者: zhlv | 来源:发表于2020-04-09 13:47 被阅读0次

NSClassFromString

 let appName = Bundle.main.infoDictionary!["CFBundleName"]

//childControllers 数组字符串  
  let childControllers : [String] = ["vc1","vc2","vc3","vc4","vc5"]
//NSClassFromString("appName+类名")
 letclass_VC =  NSClassFromString("SMHCommerce.\(childControllers.object(at:i))")as!UIViewController.Type
 letcontroller :UIViewController? = class_VC.init()

颜色相关的函数

//生成颜色
func RGBA(r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat) -> (UIColor){
    return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a)
}

//十六进制颜色值
func RGBColorFromHex(rgbValue:Int) -> (UIColor) {
    return UIColor.init(_colorLiteralRed:((Float)((rgbValue & 0xFF0000) >> 16))/255.0,
                                    green: ((Float)((rgbValue & 0xFF00) >> 8))/255.0,
                                    blue: ((Float)(rgbValue & 0xFF))/255.0 ,
                                    alpha: 1.0)
    
}
//rbg转UIColor(16进制)带透明度
func RGBAColorFromHex(rgbaValue:Int) -> UIColor {
    return UIColor.init(_colorLiteralRed:((Float)((rgbaValue & 0xFF0000) >> 16))/255.0,
                                    green: ((Float)((rgbaValue & 0xFF00) >> 8))/255.0,
                                    blue: ((Float)(rgbaValue & 0xFF))/255.0 ,
                                    alpha: ((Float)((rgbaValue & 0xFF000000) >> 24))/255.0)
}

//随机颜色
func RandomColor () ->(UIColor){
    let red = CGFloat(arc4random()%255)
    let green = CGFloat(arc4random()%255)
    let blue = CGFloat(arc4random()%255)
    return RGBA(r: red, g: green, b: blue, a:1)

}

遍历字符串


let number = "1234567890"
for num in number{
print(num)
}
//循环,带索引的
  for (index,item) in number.enumerated() {

 print(item)
            print(index)
}

重载viewcontroller

BAB6FB43C60D903602608B95C2F19692.png

最后调用这个:" super.init(nibName: nil, bundle: nil)"

Swift 异步访问缓存大小

异步访问缓存大小
textField的Placeholder 的字体大小, 颜色

  // 字体大小
 self.textField?.attributedPlaceholder = NSAttributedString.init(string:placeholder ?? "", attributes: [NSAttributedString.Key.font:UIFont.systemFont(ofSize:15),NSAttributedString.Key.foregroundColor:ColorPlacrholder])    

方法的Block的回调

  class func systemAlter(_ alertType: LZAlertType, alterTitle title: String?, message: String?, 
cancel: String?, sure: String?, dictionary: [AnyHashable : Any]?, 
cancelBlock: @escaping (_ object: Any?) -> Void, 
sureBlock: @escaping (_ object: Any?) -> Void) {

仿照微信弹框的demo

图片旋转180度, 再次复原

  UIView.animate(withDuration: 2) {
            if(isCheck){
                self.imageView.transform = CGAffineTransform.init(rotationAngle: .pi)
            } else {
                self.imageView.transform = .identity
            }
        }

相关文章

网友评论

      本文标题:swift实践笔记

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