Skip to content

Instantly share code, notes, and snippets.

View iAmrSalman's full-sized avatar

Amr Salman iAmrSalman

View GitHub Profile
@iAmrSalman
iAmrSalman / newCell.swift
Last active July 20, 2017 18:04
[insert new cell into UITableView] #uitableview #swift3
Yourarray.append([labeltext])
tableView.beginUpdates()
tableView.insertRows(at: [IndexPath(row: yourArray.count-1, section: 0)], with: .automatic)
tableView.endUpdates()
@iAmrSalman
iAmrSalman / Commpression.swift
Created July 20, 2017 18:04
[Compress image] UIImage extension to enable image compression #swift3 #compression #image
extension UIImage {
enum JPEGQuality: CGFloat {
case lowest = 0
case low = 0.25
case medium = 0.5
case high = 0.75
case highest = 1
}
/// Returns the data for the specified image in PNG format
@iAmrSalman
iAmrSalman / CompressionService.swift
Created July 20, 2017 23:06
[CompressionService] compress 'image' to 'maxSize' size #swift3 #image #compression
struct CompressionService {
/**
compress 'image' to 'maxSize' size
- Parameter image: The image to compress.
- Parameter maxSize: The maximum size in MB to image.
- Returns: A Data image with 'maxSize' applied.
@iAmrSalman
iAmrSalman / imageChange.swift
Last active July 21, 2017 02:54
[change image animation] Fade when changing UIImageView’s image #swift3 #image #animation
UIView.transition(with: self.imageView,
duration:0.5,
options: .transitionCrossDissolve,
animations: { self.imageView.image = newImage },
completion: nil)
@iAmrSalman
iAmrSalman / changeImageAnimation.swift
Created July 21, 2017 02:58
[changeImage animation] UIImageView extension to fade in UIImageView new image #swift3 #image #animation #exttension
extension UIImageView {
func changeImage(to newImage: UIImage?) {
let crossFade: CABasicAnimation = CABasicAnimation(keyPath: "contents")
crossFade.duration = 0.2
crossFade.fromValue = self.image?.cgImage
crossFade.toValue = newImage?.cgImage
self.image = newImage
self.layer.add(crossFade, forKey: "animateContents")
}
}
@iAmrSalman
iAmrSalman / UIViewExtension.swift
Last active November 9, 2017 07:46
[UIViewExtensions] extensions for UIView to reduce dev time #uiview #extension #swift3
import UIKit
public enum Shape {
case rectangle
case rounded(CGFloat)
case circular
}
extension UIView {
@IBInspectable var cornerRadius: CGFloat {
@iAmrSalman
iAmrSalman / PresentVC.swift
Created July 28, 2017 08:16
[Instantiate and Present a viewController] #swift3
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
self.present(controller, animated: true, completion: nil)
@iAmrSalman
iAmrSalman / openSettings.swift
Created July 28, 2017 19:41
[Open App Settings] #swift3 #settings #errorhandling
guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else { return }
if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
print("Settings opened: \(success)") // Prints true
})
}
@iAmrSalman
iAmrSalman / customTabBar.swift
Last active June 3, 2018 21:55
[Custom TabBar] customizing UITabBarController #tabbar #swift3 #ui
import UIKit
class RootVC: UITabBarController {
//MARK: - Propertise
let selectedColor = UIColor(red: 238 / 255.0, green: 110 / 255.0, blue: 115 / 255.0, alpha: 1)
let unselectedColor = UIColor(red: 37 / 255.0, green: 37 / 255.0, blue: 37 / 255.0, alpha: 1)
//MARK: - Life cycle
@iAmrSalman
iAmrSalman / removeTabbaritemText.swift
Created August 1, 2017 10:16
[removeTabbaritemText] #swift3 #tabbar
extension UITabBarController {
func removeTabbarItemsText() {
tabBar.items?.forEach {
$0.title = ""
$0.imageInsets = UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0)
}
}
}