Skip to content

Instantly share code, notes, and snippets.

View sourleangchhean168's full-sized avatar
🎯
Focusing

SOUR LEANGCHHEAN sourleangchhean168

🎯
Focusing
View GitHub Profile
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row + 1 == list.count {
if currentPage != totalPage{
self.getList(currentPage + 1, max_row)
}
}
}
@sourleangchhean168
sourleangchhean168 / .gitignore
Created August 20, 2019 09:51 — forked from simonexmachina/.gitignore
Example .gitignore file for iOS projects
## Build generated
build/
DerivedData
build.xcarchive
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
@sourleangchhean168
sourleangchhean168 / collectionviewmovetosection.swift
Last active April 11, 2018 13:38
CollectionView Move to Section Swift 4.1
//Swift 4.1
func moveToSection(section:Int){
if let sec = self.collectionView?.numberOfSections{
if sec > section{
let indexP = IndexPath(item: 0, section: section)
if let cv = self.collectionView{
if section == 0{
cv.scrollToItem(at: indexP, at: .centeredVertically, animated: true)
@sourleangchhean168
sourleangchhean168 / collectionView_cell_animation.swift
Created April 11, 2018 13:35
CollectionView Cell Animation in Swift 4
let cell = collectionView.cellForItem(at: indexPath)
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 5, options: [],
animations: {
cell!.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
},
completion: { finished in
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 5, options: .curveEaseInOut,
animations: {
@sourleangchhean168
sourleangchhean168 / collectionViewScroll
Created March 25, 2018 18:07 — forked from genedelisa/collectionViewScroll
UICollectionView scroll to make section header visible
/**
Scroll to make the the given section header visible.
The function scrollToItemAtIndexPath will scroll to the item and hide the section header.
Swift 3.
*/
func scrollToSection(_ section:Int) {
if let cv = self.collectionView {
let indexPath = IndexPath(item: 1, section: section)
if let attributes = cv.layoutAttributesForSupplementaryElement(ofKind: UICollectionElementKindSectionHeader, at: indexPath) {
@sourleangchhean168
sourleangchhean168 / multiple_ssh_setting.md
Created October 30, 2017 17:11 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "[email protected]"
extension UIButton{
func roundCorners(corners:UIRectCorner, radius: CGFloat){
let borderLayer = CAShapeLayer()
borderLayer.frame = self.layer.bounds
borderLayer.strokeColor = UIColor.green.cgColor
borderLayer.fillColor = UIColor.clear.cgColor
borderLayer.lineWidth = 10.5
let path = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
@sourleangchhean168
sourleangchhean168 / screenshotAlbumCount.swift
Created May 12, 2017 06:51
Get screenshot (album) count in swift
let albumsPhoto:PHFetchResult<PHAssetCollection> = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: nil)
albumsPhoto.enumerateObjects({(collection, index, object) in
if collection.localizedTitle == "Screenshots"{
let photoInAlbum = PHAsset.fetchAssets(in: collection, options: nil)
print(photoInAlbum.count) //Screenshots albums count
}
})
@sourleangchhean168
sourleangchhean168 / phAssettoUIImage.swift
Created May 12, 2017 06:50
Convert PHAsset to UIImage: 3.0.1
func getAssetThumbnail(asset: PHAsset, size: CGFloat) -> UIImage {
let retinaScale = UIScreen.main.scale
let retinaSquare = CGSize(width: size * retinaScale, height: size * retinaScale)//(size * retinaScale, size * retinaScale)
let cropSizeLength = min(asset.pixelWidth, asset.pixelHeight)
let square = CGRect(x:0, y: 0,width: CGFloat(cropSizeLength),height: CGFloat(cropSizeLength))
let cropRect = square.applying(CGAffineTransform(scaleX: 1.0/CGFloat(asset.pixelWidth), y: 1.0/CGFloat(asset.pixelHeight)))
let manager = PHImageManager.default()
let options = PHImageRequestOptions()
var thumbnail = UIImage()
options.isSynchronous = true
@sourleangchhean168
sourleangchhean168 / CustomActivityIndicator.swift
Created May 12, 2017 06:47
iOS customized activity indicator with Swift 3.0.2
@discardableResult
func customActivityIndicatory(_ viewContainer: UIView, startAnimate:Bool? = true) -> UIActivityIndicatorView {
let mainContainer: UIView = UIView(frame: viewContainer.frame)
mainContainer.center = viewContainer.center
mainContainer.backgroundColor = UIColor.init(netHex: 0xFFFFFF)
mainContainer.alpha = 0.5
mainContainer.tag = 789456123
mainContainer.isUserInteractionEnabled = false
let viewBackgroundLoading: UIView = UIView(frame: CGRect(x:0,y: 0,width: 80,height: 80))