發表文章

目前顯示的是 3月, 2012的文章

NSString 位移運算 (shift operation)

自己寫了一個簡單的位移運算 因為沒有偵測邊界 所以用try包起來 import後 會繼承在nsstring 直接使用即可 ex: NSString *temp=[[NSString alloc] initWithString:@"test"]; NSlog("Shift=> %@",[temp shift:3]); ShiftEncode.h #import @interface NSString (ShiftEncode) - (NSString*)Shift:(int)offset; @end ShiftEncode.m #import "ShiftEncode.h" @implementation NSString (ShiftEncode) - (NSString*)Shift:(int)offset { NSMutableString* decoded = [NSMutableString stringWithString:self]; NSMutableString* DecodeStr=[[NSMutableString alloc] init]; @try{ for (int i=0;i<[decoded length];i++) { UTF16Char xx=[decoded characterAtIndex:i]; if (xx==' ') { [DecodeStr appendFormat:@" "]; }else { UTF16Char newChar=xx+offset; [DecodeStr appendFormat:@"%C",newChar]; } } }@catch (NSException *EXP) { NSLog(@"NSSTRING SHIFT :%@",EXP); DecodeStr=nil; } ...

NSString 一個好用的字串縮短(截斷)程式碼 (Using lineBreakMode on NSString) NSString-truncateToSize

圖片
再UILabel上有lineBreakMode屬性 可以讓我們選擇當字串長度過長時 要截短時要截中間還是後面 不過除了UILabel以外 還有很多地方可能會用到縮排的地方 NSString-truncateToSize就是讓我們可以指定字串長度 自動斷字的程式碼 已經用interface繼承了nsstring 因此我們直接呼叫就可以 請進入下面連結下載 https://gist.github.com/906714 效果如下 使用前(自動斷字) 使用後(指定長度斷字) 範例 title = [tempStr truncateToSize:CGSizeMake(240.0, 30.0) withFont:[UIFont systemFontOfSize:17.0f] lineBreakMode:UILineBreakModeMiddleTruncation];

ios 強制畫面旋轉

有時我們的程式只支援特定的方向 所以有時需要作強制畫面的旋轉 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; //UIInterfaceOrientationPortrait < Orientation that you want

NSLog的輸出變數一覽

NSLog的輸出變數一覽 NSlog(@" your var=%@",var); Specifier Description %@ Objective-C object, printed as the string returned by  descriptionWithLocale:  if available, or  description  otherwise. Also works with  CFTypeRef  objects, returning the result of the  CFCopyDescription  function. %% '%'  character %d ,  %D , %i Signed 32-bit integer ( int ) %u ,  %U Unsigned 32-bit integer ( unsigned int ) %hi Signed 16-bit integer ( short ) %hu Unsigned 16-bit integer ( unsigned short ) %qi Signed 64-bit integer ( long long ) %qu Unsigned 64-bit integer ( unsigned long long ) %x Unsigned 32-bit integer ( unsigned int ), printed in hexadecimal using the digits 0–9 and lowercase a–f %X Unsigned 32-bit integer ( unsigned int ), printed in hexadecimal using the digits 0–9 and uppercase A–F %qx Unsigned 64-bit integer ( unsigned long long ), printed in hexadecimal using the digits 0–9 and l...