IOS开发iOS_收藏iOS开发

[精]这里面的,你懂多少?(价值998元的iOS技能未完待续..

2017-06-07  本文已影响376人  ChinaSwift

eg:
在finder中打开字体.ttf,标题显示是Bauhaus ITC。
btn1.titleLabel?.font = UIFont(name: "Bauhaus ITC", size: 18)

添加字体
class GeneralFactory: NSObject {
    static var fileManager = NSFileManager.defaultManager()
    static var currentUser = AVUser.currentUser()  
    static func addTitleWithTitle(target:UIViewController,leftTitle:String = "取消",rightTitle:String = "确定"){
        let btn1 = UIButton(frame: CGRectMake(10,20,40,20))
        btn1.setTitle(leftTitle, forState: .Normal)
        btn1.setTitleColor(MAIN_RED, forState: .Normal)
        btn1.contentHorizontalAlignment = .Left
        btn1.titleLabel?.font = UIFont(name: MY_FONT, size: 18)
        btn1.tag = 1234
        target.view.addSubview(btn1)
        btn1.addTarget(target, action: Selector("close"), forControlEvents: .TouchUpInside)
}

工厂模式的开发模式,能够极大程度上的简洁代码,避免代码的过度重复,使编程成为每一次轻松愉悦的享受。

vc1:
typealias CallBack = (title:String)->Void
class vc1:UIViewController{
    var 闭包:CallBack?
    self.闭包!(title:(self.titleTextField?.text)!)
}
vc2:
vc1.闭包 = {(string) in self.Book_Title = string}

[deinit{
print("Controller reallse")

}
如果成功析构,则没有内存泄露。
如果没有析构,没打印那句话,则表明内存泄露了。]()

guard let name = Bundle.main.infoDictionary!["CFBundleExecutable"] as? String else {  
  print("获取命名空间失败")
  return  
} 
let class: AnyClass? = NSClassFromString(name + "." + VCName) //VCName:表示试图控制器的类名  
// Swift中如果想通过一个Class来创建一个对象, 必须告诉系统这个Class的确切类型  
guard let typeClass = class as? UIViewController.Type else {  
  print("class不能当做UIViewController")
  return  
}  
let childController = typeClass.init()  
let home = storyboard.instantiateViewController(withIdentifier: “Homer”)
static func storyboardInstance() -> ThreeViewController? {
        let storyboard = UIStoryboard(name:"ThreeViewController" ,bundle: nil)
        return  storyboard.instantiateViewController(withIdentifier: "ThreeViewController") as?ThreeViewController
    }
添加支持HTTP
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), forBarMetrics: .Default)
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.tableView?.deselectRowAtIndexPath(indexPath, animated: true)
}
extension UIView {  
    func findController() -> UIViewController! {
        return self.findControllerWithClass(UIViewController.self)
    }
    func findNavigator() -> UINavigationController! {
        return self.findControllerWithClass(UINavigationController.self)
    } 
    func findControllerWithClass<T>(_ clzz: AnyClass) -> T? {
        var responder = self.next
        while(responder != nil) {
            if (responder!.isKind(of: clzz)) {
                return responder as? T
            }
            responder = responder?.next
        }   
        return nil
    }
}

介绍地址https://www.waerfa.com/sip-color-picker

eg:

extension UIScrollView{
override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  self.next?.touchesBegan(touches, with: event)
}  

注意添加subViews的顺序!

就一行
eg1:
//   下面两种方式是一个意思
imageV.animationImages = (1...4).map({ (int) -> UIImage in
         UIImage(named: "MyLucky\(int)")!
})
 imageV.animationImages = (1...4).map{
          UIImage(named: "MyLucky\($0)")!
 }
eg2:
   //   map的酸爽用法
        let mapPointArr =  pointArr.map { (i) -> BMKMapPoint in
        BMKMapPointForCoordinate(i.coordinate)
        }
        let mapPointArr = pointArr.map { BMKMapPointForCoordinate($0.coordinate)
       }

这里有老司机对map和flatMap的解说
http://www.jianshu.com/p/8a9998c137fc

     let bundlePath = (Bundle.main.resourcePath)! + “/你想获取资源所在的bundle名.bundle/"
        let bundle = Bundle(path: bundlePath)
        var tmpBundle : String?
        tmpBundle = (bundle?.resourcePath)! + "/images/icon_nav_bus.png"
        if let imagePath =  tmpBundle{
            if let image = UIImage(contentsOfFile: imagePath){
                annotationView?.image = image
            }    
        }else{
            print("---not found image---")
        }
@IBDesignable
class GRLabel:UILabel{
    @IBInspectable var cornerRadius1:CGFloat = 0{
        didSet{
            self.layer.cornerRadius = cornerRadius1
            self.layer.masksToBounds = true
        }
    }
}
let cast = ["Vivien", "Marlon", "Kim", "Karl"]
 let shortNames = cast.filter { $0.characters.count < 5 }
 print(shortNames)
// Prints "["Kim", "Karl"]"
let Dictionarys = [“a”:1,“b”:2,“c”:3]
let afterFliter = Dictionarys.filter { (item:(key: String, value: Int)) -> Bool in
            item.value == 2
        }
print(afterFliter)
//Prints [(“b”,2)]
APP Icon Gear APP Icon Gear

总结一句:你喜欢就好!

'各位邻居街坊们,点赞,打赏随意哈!'
上一篇下一篇

猜你喜欢

热点阅读