Skip to main content

Posts

Showing posts from October, 2019

Xcode 9 Vector Images

Apple đã thêm hình ảnh PDF Vector tới Xcode asset catalog trong Xcode 6. Nó là một cách tiện lợi để build hình ảnh cho độ phân giải 1x, 2x và 3x dù không có đử hình ảnh cho mỗi file. Nhưng nó không đưa cho bạn một hình ảnh vector mở rộng thực sự. Khi hình ảnh bị kéo dãn sẽ làm cho nó trở lên xấu xí và tồi tệ. Sự thay đổi trên Xcode 9 có thể giữ dữ liệu vector và scale hình ảnh. Hình ảnh mờ Để sử dụng một hình ảnh PDF, bạn thêm một hình ảnh PDF độ phân giải 1x tới asset catalog, chọn single scale và Xcode sẽ cung cấp hình ảnh 2x và 3x tại build time. Vấn đề với hình ảnh PDF là cho đến bây giờ, Xcode chỉ tạo hình ảnh scaled tại build time. Nó không hỗ trợ hình ảnh scaled tại run time. Cho ví dụ, ta có một hình ảnh ngôi sao 100 x 100 pixel, nó sẽ trong ổn nếu giữ nó ở content size bình thường. Nếu tôi thêm constrains để phóng to hình ảnh trông nó sẽ thật sự xấu xí. Đây là hình ảnh mẫu, sử dụng trạng thái Aspect Fit, scaled lên 3 lần để rộng bằng chiều rộng của iPhone 7

Tất cả Keywords trong Swift

Nay rảnh rỗi nên mình xin được mạn phép clone 1 bản từ tác giả Jordan Morgan , (bài viết gốc ở đây ) nói về tất cả keywords trong Swift, hy vọng nó sẽ giúp ích cho các bạn trong quá trình phỏng vấn cũng như trong công việc. Tuy nhiên 1 số từ mình sẽ để bản tiếng Anh, vì dịch ra nó hơi “chuối", và 1 số định nghĩa mình cũng ko dịch sát nghĩa, mà dịch theo cách hiểu của riêng mình. Có thiếu sót gì thì mình mong được các bạn bổ sung thêm :D. Declaration Keywords associatedtype : Cho phép tạo 1 tên bất kỳ cho 1 loại biến trong khai báo của 1 protocol. Biến này được qui định là loại nào khi protocol đó được adopt. protocol Entertainment { associatedtype MediaType } class Foo : Entertainment { typealias MediaType = String // Bất cứ loại nào đều được } class : là thành phần không thể thiếu trong mọi ứng dụng, chúng giúp chúng ta tổ chức và quản lý code thành những khối, nó có 1 số điểm khác struct như sau: Tính kế thừa. Cho phép ép kiểu hoặc check kiểu lúc ch

TableView: Tự động tính lại chiều cao của tableview theo nội dung của nó

Việc co dãn, tính toán chiều cao của table view một cách tự động sẽ thường xuyên gặp trong qúa trình lập trình. Hôm nay tôi sẽ chỉ cho bạn một phương pháp tuyệt vời để thực hiện điều này: 1 - Cài đặt height constraint từ storyboard . 2 - Kéo height constraint từ storyboard và tạo @IBOutlet cho nó trong file View Controller. @IBOutlet weak var tableHeight : NSLayoutConstraint ! 3 -Thêm đoạn code sau vào viewWillLayoutSubviews() override func viewWillLayoutSubviews () { super . updateViewConstraints () self . tableHeight ?. constant = self . table . contentSize . height } Nếu row cuối bị cut khi hiển thị, bạn hãy gọi viewWillLayoutSubviews() trong hàm willDisplay: func tableView ( _ tableView : UITableView , willDisplay cell : UITableViewCell , forRowAt indexPath : IndexPath ) { self . viewWillLayoutSubviews () } That's all !!!        

Fileprivate vs private: Giải thích sự khác biệt

Fileprivate vs private in Swift: The differences explained Fileprivate and private are part of the access control modifiers in Swift. These keywords, together with internal, public, and open, make it possible to restrict access to parts of your code from code in other source files and modules. The private access level is the lowest and most restrictive level whereas open access is the highest and least restrictive. The documentation of Swift will explain all access levels in detail to you, but in this blog post, I’m going to explain the differences between two close friends: fileprivate and private. Build better iOS apps faster Looking for a great mobile CI/CD solution that has tons of iOS-specific tools, smooth code signing, and even real device testing? Learn more about Bitrise’s iOS specific solutions! Open access is the highest (least restrictive) access level and private access is the lowest (most restrictive) access level. This will improve readability and mak