Skip to content

Instantly share code, notes, and snippets.

View nonstriater's full-sized avatar

移动开发小冉 nonstriater

View GitHub Profile
@nonstriater
nonstriater / gist:11107653
Last active August 29, 2015 14:00
普通字体转换成粗体
// Returns the bold version of a font. May return nil if there is no bold version.
UIFont *RNGetBoldFontForFont(UIFont *font) {
UIFont *result = nil;
CTFontRef ctFont = CTFontCreateWithName((__bridge CFStringRef)(font.fontName),
font.pointSize, NULL);
if (ctFont) {
// You can't add bold to a bold font
// (don't really need this, since the ctBoldFont check would handle it)
if ((CTFontGetSymbolicTraits(ctFont) & kCTFontTraitBold) == 0) {
if (sqlite3_open([DATABASE UTF8String], &database) == SQLITE_OK)
{
NSString *sql = [NSString stringWithFormat:@"update lpb set %@ = '%@' where level='%@'", self.typeString, self.iconString, self.levelString];
if (sqlite3_exec(database, [sql UTF8String], NULL, NULL, &error) != SQLITE_OK)
NSLog(@"LPBERROR: %@ , %s",sql, error);
sqlite3_close(database);
}
@nonstriater
nonstriater / gist:57f7ba74aa383b9cc216
Created May 4, 2014 06:10
图片强制解压缩优化技巧
图片优化技巧
- (void)decompressImage:(UIImage *)image
{
UIGraphicsBeginImageContext(CGSizeMake(1, 1));
[image drawAtPoint:CGPointZero];
UIGraphicsEndImageContext();
}
This causes the image to decompress
@nonstriater
nonstriater / gist:20ddc933f6147265f6dd
Created May 4, 2014 06:11
为UIView设置圆角(小于4个角)
为UIView设置圆角(小于4个角) UIBezi erPath + UIShapeLayer
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)]; // byRoundingCorners : 指定需要圆角的角,UIRectCorner类型
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = view2.bounds;
maskLayer.path = maskPath.CGPath;
view2.layer.mask = maskLayer;
@nonstriater
nonstriater / gist:222014229a113c2c2df8
Created May 4, 2014 06:12
从视频文件中获得一张图片(截图)
从视频文件中获得一张图片(截图)
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
gen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);
NSError *error = nil;
CMTime actualTime;
CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
@nonstriater
nonstriater / gist:6f7f166d86d0a8cbcdb3
Created May 4, 2014 06:12
iOS 获取当前WIFI名字
iOS 获取当前WIFI名字
+ (NSString *)GetCurrentWifiHotSpotName {
NSString *wifiName = nil;
NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
for (NSString *ifnam in ifs) {
NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
NSLog(@"info:%@",info);
if (info[@"SSID"]) { wifiName = info[@"SSID"]; }
}
@nonstriater
nonstriater / gist:fa4dcb03b5b8087c53e9
Last active August 29, 2015 14:00
NSLocale中取出国家country信息并按照国家名字排序
//NSLocale中取出国家country信息并按照国家名字排序
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en"];
NSArray *countryCodes = [NSLocale ISOCountryCodes];// 所有国家编码
NSMutableArray *countriesUnsorted = [[NSMutableArray alloc] initWithCapacity:countryCodes.count];
for (NSString *countryCode in countryCodes) {
NSString *displayNameString = [locale displayNameForKey:NSLocaleCountryCode value:countryCode];// 获得编码对应的国家名字
@nonstriater
nonstriater / gist:85f4e432d3f78110ca8d
Created May 4, 2014 06:13
正则表达式验证邮箱
- (BOOL) validateEmail: (NSString *) candidate {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:candidate];
}
@nonstriater
nonstriater / gist:e817dcc51952384827ae
Created May 4, 2014 06:14
Appirater 打开app时,提醒用户给应用打分
// rate
[Appirater setAppId:kAppStoreID];
[Appirater setOpenInAppStore:YES]; // 设置为NO,in-app方式打开
[Appirater setDaysUntilPrompt:1]; // 1天过后
[Appirater setUsesUntilPrompt:10]; // 使用10次
[Appirater setSignificantEventsUntilPrompt:-1];
[Appirater setTimeBeforeReminding:2];
[Appirater appLaunched:YES];
@nonstriater
nonstriater / spy.d
Last active August 29, 2015 14:16 — forked from markd2/spy.d
#!/usr/sbin/dtrace -s
/* Run like:
% sudo csh
# ./spy.d $PROCESS_ID [$INTERESTING_PROBEPROV]
Prints a line of dashes every 5 seconds to delineate different experiments.
*/
#pragma D option quiet