2014年3月31日 星期一

同時支援 iOS6 與 iOS7

  • if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
  • // Load resources for iOS 6.1 or earlier
  • } else {
  • // Load resources for iOS 7 or later
  • }

2014年3月29日 星期六

自定義NavigationBar的Back鍵文字

UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
        [self.navigationItem setBackBarButtonItem:backItem];
        

        [self.navigationController pushViewController:detailViewController animated:YES];

使用自己宣告的顏色

//在你的Class中新增一個UIColor的Category,在其中新增一些自定義的顏色

#pragma mark - Color Definition

@implementation UIColor (yourCategory)

+ (UIColor *) defaultColor
{
    return [UIColor colorWithRed:120.0/255 green:200.0/255 blue:120/255 alpha:1];
}



@end

設定TableViewCell文字顯示

self.textLabel.text = @"你要的Title";
//顏色
self.textLabel.textColor = [UIColor BlackColor];
//字型 大小
UIFont *myFont = [ UIFont fontWithName: @"Arial" size: 16.0 ];
self.textLabel.font  = myFont;

//置中
self.textLabel.textAlignment = NSTextAlignmentCenter;

在Mac OSX中製作加密的壓縮檔

打開終端機

//在Mac OSX中製作加密的壓縮檔
zip -e archivename.zip filetoprotect.txt

//在Mac OSX中製作加密的壓縮的資料夾
zip -er ~/Desktop/encrypted.zip ~/Documents/Confidential/


//要解壓縮 .xz的檔案
tar xvfJ filename.tar.xz

2014年3月28日 星期五

tableViewCell如果沒有給他textLabel的文字會視為nil

/*
tableViewCell如果沒有給他textLabel的文字,給空字串(@"")也一樣
在這裡讀到的textLabel會是nil
而不是沒有文字的textLabel
*/

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

   //因此如果我們要比對文字的話,要先給他一個文字(這裡是給空格)
   if( !cell.textLabel.text )
    {
        cell.textLabel.text = @" ";
    }
}

iOS7的TableView分格線(separator)

//在你的viewDidLoad實作

//分格線被imageView蓋住的問題
if ([self.tableView respondsToSelector:@selector(separatorInset)]) {
    [self.tableView setSeparatorInset:UIEdgeInsetsZero];
}

//分格線換顏色
self.tableView.separatorColor = [UIColor redColor];