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
typedef NS_ENUM(NSUInteger, BinaryUnit) { | |
b, | |
B, | |
KB, | |
MB, | |
GB, | |
TB, | |
PB, | |
ZB, | |
YB |
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
public enum BinaryUnit: Int { | |
case b = 0, B, KB, MB, GB, TB, PB, ZB, YB | |
} | |
public func binaryUnitTransform(value: Double, #unit: BinaryUnit) -> (value: Double, unitString: String) { | |
var raw = unit.rawValue | |
if value < 1.0 && value > 0 && unit != .b { | |
return binaryUnitTransform(value * 1024.0, unit: BinaryUnit(rawValue: --raw)!) | |
} else if value > 1024.0 && unit != .YB { | |
return binaryUnitTransform(value / 1024.0, unit: BinaryUnit(rawValue: ++raw)!) |
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
#!/bin/bash | |
#-------------------------------------------- | |
# 功能:编译xcode项目并打ipa包 | |
# 使用说明: | |
# 编译project | |
# ipa-build <project directory> [-c <project configuration>] [-o <ipa output directory>] [-t <target name>] [-n] [-p <platform identifier>] | |
# 编译workspace | |
# ipa-build <workspace directory> -w -s <schemeName> [-c <project configuration>] [-n] | |
# |
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
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender { | |
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ | |
[[UIMenuController sharedMenuController] setMenuVisible:NO animated:NO]; | |
}]; | |
if (action == @selector(paste:)) | |
return NO; | |
if (action == @selector(select:)) | |
return NO; | |
if (action == @selector(selectAll:)) | |
return NO; |
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
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string | |
{ | |
NSString *result = [textField.text stringByReplacingCharactersInRange:range withString:string]; | |
// do something | |
return YES; | |
} |
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
func printDirectoryContent(path: String) { | |
let contents = NSFileManager.defaultManager().contentsOfDirectoryAtPath(path, error: nil) | |
if let files = contents { | |
for file in files as! [String] { | |
let filePath = path.stringByAppendingPathComponent(file) | |
let attributes = NSFileManager.defaultManager().attributesOfItemAtPath(filePath, error: nil)! | |
if attributes[NSFileType] as! String == NSFileTypeDirectory { | |
printDirectoryContent(filePath) | |
} else { | |
if NSFileManager.defaultManager().isUbiquitousItemAtURL(NSURL(fileURLWithPath: filePath)!) { |
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
- (void)drawRect:(CGRect)rect | |
{ | |
const CGFloat frequency = 25.0f; | |
const CGFloat amplitude = 5.0f; | |
const CGFloat baseLineHeight = 50.0f; // if base line height equal to amplitude, the sawtooth is on the edge of the view | |
// Drawing code | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSaveGState(context); | |
CGContextSetLineWidth(context, 2.0f); // set line width | |
CGContextSetStrokeColorWithColor(context, [UIColor purpleColor].CGColor); // set stroke color |
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
- (void)viewWillAppear:(BOOL)animated | |
{ | |
[super viewWillAppear:animated]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; | |
} | |
- (void)viewWillDisappear:(BOOL)animated | |
{ | |
[super viewWillDisappear:animated]; | |
[[NSNotificationCenter defaultCenter] removeObserver:self]; |
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
#pragma mark - UIScrollViewDelegate | |
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView | |
{ | |
NSInteger pageIndex = lroundf(scrollView.contentOffset.x / CGRectGetWidth(scrollView.frame)); | |
pageControl.currentPage = pageIndex; | |
} |