Giter Site home page Giter Site logo

ios-swift-learning-notes's Introduction

Welcome to GitHub Pages

You can use the editor on GitHub to maintain and preview the content for your website in Markdown files.

Whenever you commit to this repository, GitHub Pages will run Jekyll to rebuild the pages in your site, from the content in your Markdown files.

Markdown

Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for

Syntax highlighted code block

# Header 1
## Header 2
### Header 3

- Bulleted
- List

1. Numbered
2. List

**Bold** and _Italic_ and `Code` text

[Link](url) and ![Image](src)

For more details see GitHub Flavored Markdown.

Jekyll Themes

Your Pages site will use the layout and styles from the Jekyll theme you have selected in your repository settings. The name of this theme is saved in the Jekyll _config.yml configuration file.

Support or Contact

Having trouble with Pages? Check out our documentation or contact support and we’ll help you sort it out.

ios-swift-learning-notes's People

Contributors

imzyf avatar

Watchers

 avatar  avatar  avatar

ios-swift-learning-notes's Issues

UIAlertController alert 弹框提示

https://stackoverflow.com/questions/24022479/how-would-i-create-a-uialertview-in-swift

let alertView = UIAlertController(title: "无法访问您的麦克风", message: "请到设置 -> 隐私 -> 麦克风 ,打开访问权限", preferredStyle: .alert)
alertView.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
alertView.addAction(UIAlertAction(title: "好的", style: .default, handler: nil))
                
self.present(alertView, animated: true, completion: nil)

fileprivate open 访问控制

http://www.jianshu.com/p/604305a61e57

现在的访问权限则依次为:open,public,internal,fileprivate,private。
有的人会觉得访问权限选择的增加加大了语言的复杂度。但是如果我们思考swift语言的设计目标之一就是一门安全的语言(“Designed for Safety”)就能理解这次的改动。更加明确清晰的访问权限控制可以使程序员表达出更准确的意图,当然也迫使在编码时思考的更加深入。

作者:没故事的卓同学
链接:http://www.jianshu.com/p/604305a61e57
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

UIColor init 十六进制

extension UIColor {
    // 用数值初始化颜色,便于生成设计图上标明的十六进制颜色
    convenience init(valueRGB: UInt, alpha: CGFloat = 1.0) {
        self.init(
            red: CGFloat((valueRGB & 0xFF0000) >> 16) / 255.0,
            green: CGFloat((valueRGB & 0x00FF00) >> 8) / 255.0,
            blue: CGFloat(valueRGB & 0x0000FF) / 255.0,
            alpha: alpha
        )
    }
}

StatusBar 相关

显示 隐藏 样式 动画

plist 中的 UIViewControllerBasedStatusBarAppearance 设置为 no 或者移除

setStatusBarStyle 不再使用

    override var prefersStatusBarHidden: Bool {
        return true
    }

String 替换、过滤、去掉空格、分割、拼接、字符串截取

http://www.jianshu.com/p/26d9201ef479

let s = " / 2 3 4 ? / "
    // 替换
    print("空格替换成-:", s.replacingOccurrences(of: " ", with: "-"))
    // 过滤
    print("空格过滤掉:", s.replacingOccurrences(of: " ", with: ""))
    // 去首尾空格
    print("去掉空格:", s.trimmingCharacters(in: .whitespaces))
    // 分割
    print("分割:", s.components(separatedBy: "/"))
    // 拼接
    let a = ["1", "2", "3"]
    print("拼接:", a.joined(separator: "-"))

设置 UIView 圆角和阴影

// 设置圆角和边框
self.buyPrompt.layer.cornerRadius = 6.0
self.buyPrompt.layer.borderColor = UIColor.lightGray.cgColor
self.buyPrompt.layer.borderWidth = 0.5

// 设置阴影
self.buyPrompt.layer.shadowColor = UIColor.lightGray.cgColor
self.buyPrompt.layer.shadowOpacity = 0.8
self.buyPrompt.layer.shadowRadius = 0.6
self.buyPrompt.layer.shadowOffset = CGSize(width: 0, height: 10)

CGRect 缩放、移动

CGRectInset 的使用方法:

//CGRectInset 将原来的矩形放大或者缩小,正表示缩小,负表示放大。
        CGRect rect = CGRectMake(80, 50, 130, 100);
        /**
         *  @param rect 以rect为中心 放大或缩小
         *  @param -20  X轴方向放大两个20
         *  @param 30   Y轴方向缩小两个30
         */
        CGRect upRect = CGRectInset(rect, -20, 30);
        NSLog(@"%@", NSStringFromRect(upRect));

        //输出结果:{{20, 80}, {170, 40}}

CGRectoffset的使用方法:

//CGRectOffset 将原来的左上角点的坐标变化
CGRect rect = CGRectMake(80, 50, 130, 100);
/**以左上角为顶点
* @param rect <#rect description#>
* @param -20 X坐标左移20
* @param 30 Y坐标上移30
宽度和高度不变
*/
CGRect upRect = CGRectOffset(rect, -20, 30);
NSLog(@"%@",NSStringFromRect(upRect));
//输出结果: {{60, 80}, {130, 100}}

作者:醉春风
链接:http://www.jianshu.com/p/26b85bff859a
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

editActionsForRowAt TableViewCell 侧滑

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let deleteAction = UITableViewRowAction(style: .default, title: "Delete") { (action, index) in
            debugPrint("\(index.row)-Delete")
        }
        deleteAction.backgroundColor = UIColor.red
        
        let moreAction = UITableViewRowAction(style: .normal, title: "👍") { (action, index) in
            debugPrint("\(index.row)-More")
        }
        moreAction.backgroundColor = UIColor.lightGray
        
        return [deleteAction, moreAction]
    }

UICollectionViewCell 同时加圆角和阴影

http://qingqinghebiancao.github.io/2016/01/12/iOS%E5%BC%80%E5%8F%91%E5%B0%8F%E6%8A%80%E5%B7%A7/

https://stackoverflow.com/questions/13505379/adding-rounded-corner-and-drop-shadow-to-uicollectionviewcell

self.contentView.layer.cornerRadius = 2.0
self.contentView.layer.borderWidth = 1.0
self.contentView.layer.borderColor = UIColor.clear.cgColor
self.contentView.layer.masksToBounds = true

self.layer.shadowColor = UIColor.lightGray.cgColor
self.layer.shadowOffset = CGSize(width: 0, height: 2.0)
self.layer.shadowRadius = 2.0
self.layer.shadowOpacity = 1.0
self.layer.masksToBounds = false
self.layer.shadowPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: self.contentView.layer.cornerRadius).cgPath

CGPath 获取上面的 CGPoints

https://stackoverflow.com/questions/12992462/how-to-get-the-cgpoints-of-a-cgpath

extension CGPath {

    func forEach( body: @convention(block) (CGPathElement) -> Void) {
        typealias Body = @convention(block) (CGPathElement) -> Void
        let callback: @convention(c) (UnsafeMutableRawPointer, UnsafePointer<CGPathElement>) -> Void = { (info, element) in
            let body = unsafeBitCast(info, to: Body.self)
            body(element.pointee)
        }
        print(MemoryLayout.size(ofValue: body))
        let unsafeBody = unsafeBitCast(body, to: UnsafeMutableRawPointer.self)
        self.apply(info: unsafeBody, function: unsafeBitCast(callback, to: CGPathApplierFunction.self))
    }


    func getPathElementsPoints() -> [CGPoint] {
        var arrayPoints : [CGPoint]! = [CGPoint]()
        self.forEach { element in
            switch (element.type) {
            case CGPathElementType.moveToPoint:
                arrayPoints.append(element.points[0])
            case .addLineToPoint:
                arrayPoints.append(element.points[0])
            case .addQuadCurveToPoint:
                arrayPoints.append(element.points[0])
                arrayPoints.append(element.points[1])
            case .addCurveToPoint:
                arrayPoints.append(element.points[0])
                arrayPoints.append(element.points[1])
                arrayPoints.append(element.points[2])
            default: break
            }
        }
        return arrayPoints
    }

    func getPathElementsPointsAndTypes() -> ([CGPoint],[CGPathElementType]) {
        var arrayPoints : [CGPoint]! = [CGPoint]()
        var arrayTypes : [CGPathElementType]! = [CGPathElementType]()
        self.forEach { element in
            switch (element.type) {
            case CGPathElementType.moveToPoint:
                arrayPoints.append(element.points[0])
                arrayTypes.append(element.type)
            case .addLineToPoint:
                arrayPoints.append(element.points[0])
                arrayTypes.append(element.type)
            case .addQuadCurveToPoint:
                arrayPoints.append(element.points[0])
                arrayPoints.append(element.points[1])
                arrayTypes.append(element.type)
                arrayTypes.append(element.type)
            case .addCurveToPoint:
                arrayPoints.append(element.points[0])
                arrayPoints.append(element.points[1])
                arrayPoints.append(element.points[2])
                arrayTypes.append(element.type)
                arrayTypes.append(element.type)
                arrayTypes.append(element.type)
            default: break
            }
        }
        return (arrayPoints,arrayTypes)
    }
}

CGFloat、CGPoint、CGSize和CGRect

http://www.cnblogs.com/chivas/archive/2012/05/16/2504006.html

https://developer.apple.com/documentation/coregraphics/cggeometry

CGFloat: 浮点值的基本类型
CGPoint: 表示一个二维坐标系中的点
CGSize: 表示一个矩形的宽度和高度
CGRect: 表示一个矩形的位置和大小

typedef float CGFloat;// 32-bit
typedef double CGFloat;// 64-bit

struct CGPoint {
    CGFloat x;
    CGFloat y;
};
typedef struct CGPoint CGPoint;

struct CGSize {
    CGFloat width;
    CGFloat height;
};
typedef struct CGSize CGSize;

struct CGRect {
    CGPoint origin;
    CGSize size;
};
typedef struct CGRect CGRect;

注意:CGRect数据结构的高度和宽度可以是负数。例如,一个矩形的原点是[0.0,0.0]和大小是[10.0,10.0]。这个矩形完全等同原点是[10.0,10.0]和大小是[-10.0,-10.0]的矩形。

UITableView 属性设置

注册 cell

self.register(UITableViewCell.self, forCellReuseIdentifier: "dialogue_cell")

动态高度

self.estimatedRowHeight = 44.0;
self.rowHeight = UITableViewAutomaticDimension

去除分割线

self.separatorStyle = .none

手势 - Gesture Recognizer

        // 单击
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissClose))
        tapGesture.require(toFail: doubleTapGesture)

UITapGestureRecognizer - 传值

https://stackoverflow.com/questions/38445262/pass-parameter-with-uitapgesturerecognizer

class ViewController: UIViewController {

    @IBOutlet weak var label1: UILabel!
    @IBOutlet weak var image: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        image.userInteractionEnabled = true;
        let tappy = MyTapGesture(target: self, action: #selector(self.tapped(_:)))
        image.addGestureRecognizer(tappy)
        tappy.title = "val"
    }

    func tapped(sender : MyTapGesture) {
        print(sender.title)
        label1.text = sender.title
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

class MyTapGesture: UITapGestureRecognizer {
    var title = String()
}

隐藏水平滚动条

scrollView.showsVerticalScrollIndicator = FALSE;
scrollView.showsHorizontalScrollIndicator = FALSE;

NavigationBar 相关

let textAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
        navigationController?.navigationBar.titleTextAttributes = textAttributes

strokeStart strokeEnd

http://www.cnblogs.com/HypeCheng/p/4172253.html

1 keyPath = strokeStart 动画的fromValue = 0,toValue = 1
表示从路径的0位置画到1 怎么画是按照清除开始的位置也就是清除0 一直清除到1 效果就是一条路径慢慢的消失

2 keyPath = strokeStart 动画的fromValue = 1,toValue = 0
表示从路径的1位置画到0 怎么画是按照清除开始的位置也就是1 这样开始的路径是空的(即都被清除掉了)一直清除到0 效果就是一条路径被反方向画出来

3 keyPath = strokeEnd 动画的fromValue = 0,toValue = 1
表示 这里我们分3个点说明动画的顺序 strokeEnd从结尾开始清除 首先整条路径先清除后2/3,接着清除1/3 效果就是正方向画出路径

4 keyPath = strokeEnd 动画的fromValue = 1,toValue = 0
效果就是反方向路径慢慢消失

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.