본문 바로가기

Programming/Swift13

[iOS Dev Tip] Status bar color whenever you have dark background, you need to set the status bar color as white. In order to make this happen, you can use following function in your vc. override var preferredStatusBarStyle: UIStatusBarStyle{ return .lightContent } However if your view controller is rooted by navigation controller, this method does not work. Instead you can use this settings. navigationController?.navigationBa.. 2021. 9. 3.
[Readable Coding Practice] How to make swiping view controller with swiping menu tab bar You can make swiping views with swiping menu bar by using collectionviews. This is the viewcontroller that app starts with. import UIKit class BaseViewController: UICollectionViewController { let menuBar: MenuBar = { let menuBar = MenuBar() //menuBar.vc = self menuBar.translatesAutoresizingMaskIntoConstraints = false return menuBar }() let backgroundColor: [UIColor] = [.brown, .blue, .darkGray, .. 2021. 8. 1.
[Readable Coding Practice] eliminate empty UItableView cells extension UITableView { func removeExcessCells() { tableFooterView = UIView(frame: .zero) } } By applying this code, you can make your tableview look like following pictures. 2021. 6. 28.
[Readable Code Practice] tableView Cell slide and delete func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { guard editingStyle == .delete else {return} datas.remove(at: indexPath.row) tableView.deleteRows(at: [indexPath], with: .left) } 2021. 6. 28.
[Readable Coding Practice] Show and dismiss loading signals fileprivate var containerView: UIView! extension UIViewController { func showLoadingView() { containerView = UIView(frame: view.bounds) view.addSubview(containerView) containerView.backgroundColor = .systemBackground containerView.alpha = 0 UIView.animate(withDuration: 0.25) { containerView.alpha = 0.8 } let activityIndicator = UIActivityIndicatorView(style: .large) containerView.addSubview(acti.. 2021. 6. 19.
[Readable Coding Practice] UIScrollView Pagination When you are working with REST API and and pulling out data from it, you sometimes cannot take all of the data down to your VC. In this case, by using pagination, you can show the data page by page. func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) { let offsetY = scrollView.contentOffset.y let contentHeight = sc.. 2021. 6. 19.
[Readable Coding Practice] Image Caching One of the best ways to reuse image data that you have already downloaded from network is image caching. By applying image caching, you can prevent slow app performance such as lagging. class GFAvatarImageView: UIImageView { static let cache = NSCache() } func downloadImage(from urlString: String) { let cacheKey = NSString(string: urlString) if let image = GFAvatarImageView.cache.object(forKey: .. 2021. 6. 19.
[Readable Coding Practice] Fetching data from REST API with URLSession In order to provide data from network, I usually use singleton class. In the class I make a data fetching function. Coding this function usually gets messy and hard to read. I used enum to make codes in the function more readable. class NetworkManager { static let shared = NetworkManager() let baseUrl = "http://api.github.com/users/" private init(){ } func getFollowers(for username: String, page.. 2021. 6. 18.
How to setup UITabBar programmatically Set like this in scenedelegate class func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { window?.rootViewController = BaseViewController() guard let _ = (scene as? UIWindowScene) else { return } } You need to make a baseViewController that can hold viewcontrollers. import UIKit class BaseViewController: UITabBarController { .. 2021. 6. 6.