2014年1月28日 星期二

layer設圓角、陰影畫黑框

sampleView.layer.cornerRadius = 10.5; // 圓角的弧度
sampleView.layer.masksToBounds = YES; //只留圓角內的背景,不加的話背景會超過圓角。
//它的意思是layer的效果只在laye的範圍內才有效,意思是如果你加了它,你設定的陰影效果就永遠不會出現。


//陰影畫黑框
self.closeButton.image = UIImage(named: PhotoNode.CLOSE_BUTTON_BG)
self.closeButton.layer.shadowRadius = 1.0
self.closeButton.layer.shadowOpacity = 1

self.closeButton.layer.shadowOffset = CGSizeZero

2014年1月27日 星期一

OSX好用小技巧

//新增位於資料夾位置的終端機視窗
//把第一項勾起來,即可在滑鼠右鍵->服務->新增位於資料夾位置的終端機視窗


//在Finder中顯示隱藏檔案
顯示隱藏檔案:defaults write com.apple.finder AppleShowAllFiles TRUE;\killall Finder
不顯示隱藏檔案:defaults write com.apple.finder AppleShowAllFiles FALSE;\killall Finder

2014年1月24日 星期五

iOS7背景存活時間

//沒設定背景執行
直接掛起

//被服務喚醒(藍牙,音樂,GPS等等)
十秒鐘後被掛起

2014年1月19日 星期日

JSON string 轉 nsdictionary 或 nsarray

-(id)_JSONParser:(NSString*)JSONString{
    
    NSData* jsonData = [JSONString dataUsingEncoding:NSUTF8StringEncoding];
    
    NSError* error = nil;
    NSArray* jsonArray = nil;
    NSDictionary* jsonDictionary = nil;
    if (jsonData) {
        id _jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData                                                 options:NSJSONReadingMutableContainers error:&error];
        if ([_jsonObject isKindOfClass:[NSDictionary class]]) {
            jsonDictionary = (NSDictionary*)_jsonObject;
            NSLog(@"%@",jsonDictionary);
            return jsonDictionary;
        }else if ([_jsonObject isKindOfClass:[NSMutableArray class]]) {
            jsonArray = (NSArray*)_jsonObject;
            NSLog(@"%@",jsonArray);
            return jsonArray;
        }
    }
    return nil;

}

2014年1月16日 星期四

NSLog的格式

  • NSLog:雙引號所括起來的為格式化字串,@符號表示為 Objective-C物件型態:其他用法類似 C 語言 printf 函式
  • \n : 換行
  • \t  : TAB功能
  • %-ni : 整數欄位寬,預設向右靠齊,負號表示向左靠齊,n 為印出位數
  • %-nc : 字元欄位寬,預設向右靠齊,負號表示向左靠齊,n為印出位數
  • %-m.nf : 浮點數欄位寬,預設向右靠齊,負號表示向左靠齊,m 為包含小數點前包含小數點的總位數,n 為小數點後的位數
  • %i : int
  • %f : float
  • %d : double
  • %c : char

微博取用戶資料

先Oauth2認證後,取得tokenID,然後依照/users/show的參數文件填入uid跟tokenID
http://api.weibo.com/2/users/show.json?uid=1904178193&access_token=2.00zBrJ2EjQ8zzC15a429a8ff2pybUD&source=2045436852

PS,重點是要加上appkey,但這邊很GY害我搞很久的點是,它用source代表appkey,降子取名誰知道啊!翻桌

//20140121
PS,突然發現他的網址改成https了,現在用http開頭是不會通的

當你要跟微博互動時,分為下面二個部份
一、還沒拿到Token時,要利用微博App去跟微博要Token

#pragma mark- WeiboSDKDelegate
//微博App來跟我們寫的App要資料,會觸發這裡,你可以透過[WeiboSDK sendResponse:]回傳資料回去
- (void)didReceiveWeiboRequest:(WBBaseRequest *)request

//這裡是用來接,微博App收到我們的請求的所發出的callback
- (void)didReceiveWeiboResponse:(WBBaseResponse *)response
#pragma mark- WBHttpRequestDelegate


二、當拿到Token以後,就不用透過微博App,而可以直接HttpRequest跟微博互動

//當你用這個方法去呼叫時[WBHttpRequest requestWithAccessToken:...],就會call back回下面的Delegate
#pragma mark- WBHttpRequestDelegate
-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

- (void)request:(WBHttpRequest *)request didFinishLoadingWithResult:(NSString *)result

2014年1月10日 星期五

iOS7 navigation bar會透過去的問題

//解決iOS 7以上版面會跑掉的問題
+(void) setViewControllerTranslucent:(UIViewController *)viewController{
    
    if( [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f )
    {
        viewController.edgesForExtendedLayout = UIRectEdgeNone;
        if (viewController.navigationController) {
            viewController.navigationController.navigationBar.translucent = NO;
        }
        if (viewController.tabBarController) {
            viewController.tabBarController.tabBar.translucent = NO;
        }
    }
}