Skip to content

Instantly share code, notes, and snippets.

originTextArray=[NSMutableArray arrayWithCapacity:0];
transTextArray=[NSMutableArray arrayWithCapacity:0];
NSString *rex=@"<[^>]*?>([^<]*)";
NSArray *r=[self.item.summary arrayOfCaptureComponentsMatchedByRegex:rex];
BOOL judge=YES;
for(NSArray *tmp in r){
NSString *content=[tmp objectAtIndex:1];
//过滤连续标签中间的空内容
@lqik2004
lqik2004 / gist:3155956
Created July 21, 2012 14:30
设置UITextView Padding
//设置padding
-(void) padding{
//padding大小(top,left,bottom,right)
UIEdgeInsets padding = UIEdgeInsetsMake(0, 15, 0, 15);
_textView.contentInset = padding;
CGRect frame = _textView.frame;
// must change frame before bounds because the text wrap is reformatted based on frame, don't include the top and bottom insets
CGRect insetFrame = UIEdgeInsetsInsetRect(frame, UIEdgeInsetsMake(0, padding.left, 0, padding.right));
@lqik2004
lqik2004 / gist:3159157
Created July 22, 2012 10:05
Custom CoreText Fonts
NSString *fontPath = [[NSBundle mainBundle] pathForResource:_fontName ofType:@"otf"];
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithFilename([fontPath UTF8String]);
// 从DataProvider创建字体
CGFontRef theCGFont =CGFontCreateWithDataProvider(fontDataProvider);
CTFontRef theCTFont=CTFontCreateWithGraphicsFont(theCGFont,_fontSize,NULL,NULL);
CFRelease(theCGFont);
CFRelease(fontDataProvider);
//创建AttributeString
attrString=[[NSMutableAttributedString alloc]initWithString:self.text];
//设置字体及大小
@lqik2004
lqik2004 / gist:3255863
Created August 4, 2012 08:21
git pbxproj
#!/bin/sh
projectfile=`find -d . -name 'project.pbxproj'`
projectdir=`echo *.xcodeproj`
projectfile="${projectdir}/project.pbxproj"
tempfile="${projectdir}/project.pbxproj.out"
savefile="${projectdir}/project.pbxproj.mergesave"
cat $projectfile | grep -v "<<<<<<< HEAD" | grep -v "=======" | grep -v "^>>>>>>> " > $tempfile
cp $projectfile $savefile
@lqik2004
lqik2004 / gist:3345155
Created August 14, 2012 00:34
AutoScroll
#pragma mark -KeyBoard Notifications
-(void) registerForKeyBoardNotification{
//键盘出现时发出信息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
//键盘消失时发出信息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
//called when uikeyboarddidshownotification is sent.
-(void)keyboardWasShown:(NSNotification *)noti{
@lqik2004
lqik2004 / gist:3606931
Created September 3, 2012 05:25
GetPixelColorAtLocation
- (UIColor *) getPixelColorAtLocation:(CGPoint)point {
UIColor* color = nil;
CGImageRef inImage = self.image.CGImage;
// Create off screen bitmap context to draw the image into. Format ARGB is 4 bytes for each pixel: Alpa, Red, Green, Blue
CGContextRef cgctx = [self createARGBBitmapContextFromImage:inImage];
if (cgctx == NULL) {
return nil; /* error */
}
size_t w = CGImageGetWidth(inImage);
@lqik2004
lqik2004 / gist:3616362
Created September 4, 2012 03:55
Convert Text2Mobi
#!/bin/bash
bangzhu (){
cat << EOF
用法: `basename $0` 文件名 [书名] [作者]
其中文件名是必须的,书名、作者什么的可以不添加,书名默认为文件名。作者则留空。至于出版社什么的就都浮云了。其实修改也很简单,但是我不需要所以就从简了。
EOF
}
@lqik2004
lqik2004 / gist:3780365
Created September 25, 2012 06:56
getRelativePath
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import decimal
path1='/Users/liuchao/Desktop/hah.mp3'
paht2='/Users/liuchao/Desktop/EZ/EzRead.py'
def get_Relative_Path(path1,path2):
@lqik2004
lqik2004 / gist:4155096
Created November 27, 2012 16:04
从真实GPS坐标获取百度地图坐标
CLLocationManager获取的坐标是由google坐标系得到的坐标,转化为百度坐标系百度有在官方API未公开实际存在的接口做转换。
/**
*坐标转换函数,从原始GPS坐标,mapbar坐标转换成百度坐标
*@param coorWgs84 待转换的原始GPS坐标,或者mapbar的坐标
*@return 返回的NSDictionry中包含“x”,“y”字段,各自对应经过base64加密之后的x,y坐标
*/
UIKIT_EXTERN NSDictionary* BMKBaiduCoorForWgs84(CLLocationCoordinate2D coorWgs84);
/**
*坐标转换函数,从google坐标,51地图坐标,mapabc坐标转换为百度坐标(51地图坐标需要显出10000)