This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIView { | |
func allConstraints() -> [NSLayoutConstraint] { | |
var constraints = [NSLayoutConstraint]() | |
constraints += self.constraints | |
var superview = self.superview | |
while superview != nil { | |
for c in superview!.constraints { | |
if c.firstItem as? UIView == self || c.secondItem as? UIView == self { | |
constraints.append(c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSLayoutConstraint.activateConstraints(constraints) | |
UIView.animateWithDuration(0.5) { | |
self.view.layoutIfNeeded() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let asset = AVURLAsset(URL: NSURL(string: self.scheduleCelebrityGame.videoLink!)!, options: nil) | |
let imgGenerator = AVAssetImageGenerator(asset: asset) | |
do { | |
let cgImage = try imgGenerator.copyCGImageAtTime(CMTimeMake(0, 1), actualTime: nil) | |
let uiImage = UIImage(CGImage: cgImage, scale: CGFloat(1.0), orientation: UIImageOrientation.Right) | |
let uiImageJPEG = UIImageJPEGRepresentation(uiImage, 1.0)! | |
} catch { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ObjC | |
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { | |
BOOL result = YES; | |
NSString *prospectiveText = [textField.text stringByReplacingCharactersInRange:range withString:string]; | |
if ([textField isEqual:self.numberTextField]) { | |
if (string.length > 0) { | |
NSCharacterSet *disallowedCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"].invertedSet; | |
BOOL replacementStringIsLegal = [string rangeOfCharacterFromSet:disallowedCharacterSet].location == NSNotFound; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//U@nCM: catch remote event here because it can be always the first responder. | |
// make sure we can recieve remote control events | |
- (BOOL)canBecomeFirstResponder { | |
return YES; | |
} | |
- (void)remoteControlReceivedWithEvent:(UIEvent *)event { | |
[kSoundManager.musicPlayerVC remoteControlReceivedWithEvent:event]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dispatch_async(dispatch_get_main_queue(), ^{ | |
NSString *script = @"var videos = document.querySelectorAll(\"video\"); for (var i = videos.length - 1; i >= 0; i--) { videos[i].pause(); };"; | |
[_webTrailer stringByEvaluatingJavaScriptFromString:script]; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myLabel.backgroundColor = UIColor.greenColor() | |
myLabel.text = "What Do I Want to Do?(Select One)" | |
myLabel.adjustsFontSizeToFitWidth = true | |
myLabel.minimumScaleFactor = 0.1 | |
let attributes = [NSFontAttributeName : myLabel.font] | |
let attributedString = NSMutableAttributedString(string:textString, attributes:attributes) | |
let context = NSStringDrawingContext() | |
context.minimumScaleFactor = myLabel.minimumScaleFactor | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Photos | |
func saveVideoIntoPhotosAppWithURL(videoURL: NSURL, completionHandler: ()->(), errorHandler: (error: NSError)->()) { | |
switch PHPhotoLibrary.authorizationStatus() { | |
case PHAuthorizationStatus.NotDetermined: | |
PHPhotoLibrary.requestAuthorization({ (authorizationStatus) in | |
dispatch_async(dispatch_get_main_queue(), { | |
self.saveVideoIntoPhotosAppWithURL(videoURL, completionHandler: completionHandler, errorHandler: errorHandler) | |
}) | |
}) |