Skip to content

Instantly share code, notes, and snippets.

Answer to a stackoverflow question.
@JeOam
JeOam / rectToRound.md
Last active August 29, 2015 14:01
UIImageView template
// .h
@property (strong, nonatomic) IBOutlet UIImageView *logoImageView;

// .m
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
 
@JeOam
JeOam / keyWindow.md
Last active August 29, 2015 14:01
[[UIApplication sharedApplication] keyWindow]

查找应用程序的主窗口对象。一般情况就是 UIWindow

当然一个应用程序可以有多个 window,键盘是一个 window

[[UIApplication sharedApplication] keyWindow]就是查找当前应用程序的主 window。

via :here

@JeOam
JeOam / ifContainsChinese.m
Created May 30, 2014 10:10
判断字符串中是否包含汉字
- (BOOL) containsChinese:(NSString *)str {
for(int i = 0; i < [str length]; i++) {
int a = [str characterAtIndex:i];
if( a > 0x4e00 && a < 0x9fff)
return TRUE;
}
return FALSE;
}
@JeOam
JeOam / shaked.m
Created June 5, 2014 02:18
监听手机“摇一摇”动作
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake)
{
NSLog(@"shaked");
}
}
@JeOam
JeOam / dayOfTheWeek.m
Last active August 29, 2015 14:02
How do I get the day of the week in Objective-C?
- (void)viewDidLoad
{
NSDate *currentDate = [NSDate date];
NSLog(@"Current Date: %@", currentDate);
// Outputs current day of week as a string in locale dependent on current regional settings.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEEE"];
NSLog(@"The day of the week: %@", [dateFormatter stringFromDate:[NSDate date]]);
@JeOam
JeOam / UIColor+RandomColor.h
Last active August 29, 2015 14:02
为 UIColor 类增加 RandomColor 方法
//.h
#import <UIKit/UIKit.h>
@interface UIColor (RandomColor)
+(UIColor *) randomColor;
@end
//.m
@JeOam
JeOam / swift.md
Created June 6, 2014 18:11
use swift in Terminal

if you don't want to mess up your current dev environment, you can just run:

$ /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift

Alternatively:

sudo xcode-select -switch /Applications/Xcode6-Beta.app/Contents/Developer

then you can do one of these two:

xcrun swift

@JeOam
JeOam / NetworkReachability.m
Last active August 29, 2015 14:02
提示网络状况
#import <AFNetworkReachabilityManager.h>
#import <MBProgressHUD.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
@JeOam
JeOam / mobileprovision.sh
Created June 9, 2014 15:49
get the Provisioning Profiles。下载 .mobileprovision 文件,然后拖拽到 iTunes 里面,这样会保留 .mobileprovision 的文件名,而不是自动生成的 SHA1 hash 值做文件名
cd ~/Library/MobileDevice/Provisioning\ Profiles