9 Notes September 2021
1. Navigate right and left tabbar file in Xcode 12 and new verison
Source: https://medium.com/@andrea.toso/uicollectionviewcell-dynamic-height-swift-b099b28ddd23
⌘ ⇧ [ or ] to navigate left and right of the tabs.
source: https://samwize.com/2020/08/21/navigating-xcode-12-and-tabs/
source: https://samwize.com/2020/08/21/navigating-xcode-12-and-tabs/
2. Change UIView width size without (.constant)
when I need to change width side but the (.xib) not need to change because use another class
so for this change I'll use programatically.
so for this change I'll use programatically.
import UIKit
class ComposerViewController: UIViewController {
@IBOutlet weak var tabelView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
setupTableView()
}
func setupTableView() {
tabelView.register(cellType: TestTableViewCell.self)
tabelView.dataSource = self
tabelView.delegate = self
}
}
extension ComposerViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tabelView.dequeueReusableCell(with: TestTableViewCell.self, for: indexPath)
if indexPath.row == 1 {
cell.view2.backgroundColor = .orange
cell.view2.widthAnchor.constraint(equalToConstant: 50).isActive = true
}
return cell
}
}
3. Select and Unselect tintBar color
For this case you can put this code into your tabBarcontroller file
/*
/*
tabBar.tintColor = .select
tabBar.unselectedItemTintColor = .gray
*/
*/
final class MainTabbarController: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
setupTabbar()
}
private func setupTabbar() {
tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()
tabBar.tintColor = .select
tabBar.unselectedItemTintColor = .gray
}
}
4. When Get response "UIExtendedGrayColorSpace" when debug area
This color in your code
This color in your code
UIExtendedGrayColorSpace 0 0 is "Clear"
UIExtendedGrayColorSpace 1 1 is "white"
UIExtendedGrayColorSpace 1 1 is "Black"
5. How to delay splashscreen / Launchscreen swift
Just add this code " Thread.sleep(forTimeInterval: 3) " in appdelegate or scenedelegate
Just add this code " Thread.sleep(forTimeInterval: 3) " in appdelegate or scenedelegate
//Appdelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Thread.sleep(forTimeInterval: 3)
return true
}//SceneDelegate
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
Thread.sleep(forTimeInterval: 3)
}
6. Dynamic cell for UICollectionViewCell
You don't need UICollectionViewDelegateFlowLayout’s method sizeForItemAt for set dynamic cell collection view cell, just use this code
// MARK: set dynamic size cell
var layout: UICollectionViewFlowLayout = {
let layout = UICollectionViewFlowLayout()
let width = UIScreen.main.bounds.size.width
layout.estimatedItemSize = CGSize(width: width, height: 20)
return layout
}()
override func viewDidLoad() {
super.viewDidLoad()
setupCollection()
}
private func setupCollection() {
categoryCollectionView.registerCell(CategoryCollectionViewCell.self)
categoryCollectionView.collectionViewLayout = layout // here
categoryCollectionView.dataSource = self
categoryCollectionView.delegate = self
}
Source: Author
7. Error when decode data
When request API using alamofire I get error when decode, in condition I already get data JSON
When request API using alamofire I get error when decode, in condition I already get data JSON
do {
let decoder = JSONDecoder()
let newValue = try decoder.decode(T.self, from: data)
completion?(.success(newValue))
} catch let error {
debugPrint(error)
completion?(.failure(.parsingFailure))
}
solution is fixing model response data (T.self) is response model, because found error when some key wrong type like (id: String) must be (id: Int).8. How make dynamic size UIView
I got some issue when need dynamic UIView width as UILabel inside view, have two ways for solve that with code and use design(xib/storyboard) in this time I want to use design in xib.
Equal width view and uilabel whne have 3 subviews in same line horizontal.
- For first uiview set default is (top: 0, bottom: 0, lading: 0, right: 0).
- In Second Equal widths constraint priority set 1000 for is (top: 0, bottom: 0, lading: 0, right: 0)
- For first uiview set default is (top: 0, bottom: 0, lading: 0, right: 0).
- In Second Equal widths constraint priority set 1000 for is (top: 0, bottom: 0, lading: 0, right: 0)
- Third Equal widths constraint priority set 250 for is (top: 0, bottom: 0, lading: 0, right: 0)
9. What is Final class in swift
In swift when you declare a class as being final, no other class can inherit from it. This means they can’t override your methods in order to change your behavior – they need to use your class the way it was written.
source: https://www.hackingwithswift.com/sixty/8/4/final-classes
In swift when you declare a class as being final, no other class can inherit from it. This means they can’t override your methods in order to change your behavior – they need to use your class the way it was written.
source: https://www.hackingwithswift.com/sixty/8/4/final-classes
====================================================
Handle height tableview auto height into cell
https://21zerixpm.medium.com/tableview-in-uitableviewcell-3c7cf123d969
====================================================
https://21zerixpm.medium.com/tableview-in-uitableviewcell-3c7cf123d969
====================================================
9 Notes September 2021
Reviewed by Luffyselah
on
September 08, 2021
Rating: 5