Difference between revisions of "Swift code snippets"
From Hawk Wiki
(→Adding UIRefreshControl) |
|||
Line 9: | Line 9: | ||
==[[Swift:Using UIRefreshControl]]== | ==[[Swift:Using UIRefreshControl]]== | ||
− | ==Example of fetching messages from Parse== | + | ==Swift:Example of fetching messages from Parse== |
https://gist.github.com/sandofsky/7134b1ff90d235901254 | https://gist.github.com/sandofsky/7134b1ff90d235901254 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | ==[[Swift:Auto Table Row Height]]== | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | = | + | |
− | + | ||
− | == | + | ==[[Swift:Navigation between storyboards]]== |
− | + | ||
− | + | ||
− | == | + | ==[[Swift:Notification Observer Using NSNotificationCenter]]== |
− | + | ||
− | + | ==[[Swift:Get Raw Histogram from CGImage]]== | |
− | + | ||
− | + | ==[[Swift:UIGraphics Drawing on UIView]]== | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
==Swift: Scale down CGImage== | ==Swift: Scale down CGImage== |
Revision as of 04:12, 23 March 2015
Contents
- 1 Swift Code snippts
- 1.1 Swift: Use NSUserDefaults to Store Persistence Data
- 1.2 Swift: Making Network Request Using NSURLConnection
- 1.3 Swift:Use AFNetworking setImageWithURL
- 1.4 Swift:Using UIRefreshControl
- 1.5 Swift:Example of fetching messages from Parse
- 1.6 Swift:Auto Table Row Height
- 1.7 Swift:Navigation between storyboards
- 1.8 Swift:Notification Observer Using NSNotificationCenter
- 1.9 Swift:Get Raw Histogram from CGImage
- 1.10 Swift:UIGraphics Drawing on UIView
- 1.11 Swift: Scale down CGImage
- 1.12 Swift: Convert between CGImage, CIImage and UIImage
- 1.13 Swift Detect Volumn Button Press
Swift Code snippts
Back To IOS_Swift
Swift: Use NSUserDefaults to Store Persistence Data
Swift: Making Network Request Using NSURLConnection
Swift:Use AFNetworking setImageWithURL
Swift:Using UIRefreshControl
Swift:Example of fetching messages from Parse
https://gist.github.com/sandofsky/7134b1ff90d235901254
Swift:Auto Table Row Height
Swift:Notification Observer Using NSNotificationCenter
Swift:Get Raw Histogram from CGImage
Swift:UIGraphics Drawing on UIView
Swift: Scale down CGImage
func scaleDownCGImage(image: CGImage, scale: Float) -> CGImage!{ var scaleDiv = UInt(1.0 / scale) let width = CGImageGetWidth(image) / scaleDiv let height = CGImageGetHeight(image) / scaleDiv let bitsPerComponent = CGImageGetBitsPerComponent(image) let bytesPerRow = CGImageGetBytesPerRow(image) let colorSpace = CGImageGetColorSpace(image) let bitmapInfo = CGImageGetBitmapInfo(image) let context = CGBitmapContextCreate(nil, width, height, bitsPerComponent, bytesPerRow, colorSpace, bitmapInfo) CGContextSetInterpolationQuality(context, kCGInterpolationMedium) let imgSize = CGSize(width: Int(width), height: Int(height)) CGContextDrawImage(context, CGRect(origin: CGPointZero, size: imgSize), image) return CGBitmapContextCreateImage(context) }
Swift: Convert between CGImage, CIImage and UIImage
Swift: Convert CIImage to CGImage
func convertCIImageToCGImage(inputImage: CIImage) -> CGImage! { let context = CIContext(options: nil) if context != nil { return context.createCGImage(inputImage, fromRect: inputImage.extent()) } return nil }
Swift: Convert CGImage to CIImage
func convertCGImageToCIImage(inputImage: CGImage) -> CIImage! { var ciImage = CIImage(CGImage: inputImage) return ciImage }
Swift: Convert CGImage or CIImage to UIImage
UIImage(CGImage: cgImage) UIImage(CIImage: ciImage)
Swift: Convert UIImage to CIImage
//uiImage: UIImage //Convert to CIImage var ciImage = CIImage(image: uiImage)
Swift: Convert UIImage to CGImage
To convert to CGImage, it requires 2 steps:
First convert to CIImage #Swift: Convert UIImage to CIImage.
Then convert to CGImage #Swift:_Convert_CIImage_to_CGImage
Swift Detect Volumn Button Press
Credit to http://stackoverflow.com/questions/28471481/swift-detect-volume-button-press
Detect volume button press, also hide volume HUD
import MediaPlayer //Only for hidding Volume view func listenVolumeButton(){ let audioSession = AVAudioSession.sharedInstance() audioSession.setActive(true, error: nil) audioSession.addObserver(self, forKeyPath: "outputVolume", options: NSKeyValueObservingOptions.New, context: nil) //If you want to hide Volume HUD view var volumeView: MPVolumeView = MPVolumeView(frame: CGRectZero) view.addSubview(volumeView) } override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) { if keyPath == "outputVolume"{ print("got in here") } }