IOS開發基礎知識--片段26,ios基礎知識--26

來源:互聯網
上載者:User

IOS開發基礎知識--片段26,ios基礎知識--26

1:UICollectionView如果在資料不夠一屏時上下滾動

當資料不多,collectionView.contentSize小於collectionView.frame.size的時候,UICollectionView是不會滾動的,可以增加下面代碼就可以:

self.myCollectionView.alwaysBounceVertical = YES;

 

2:畫虛線CGContextSetLineDash(豎向跟橫向)

豎向:       UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 100, 10, 100)];    [self.view addSubview:imageView1];        UIGraphicsBeginImageContext(imageView1.frame.size);   //開始畫線    [imageView1.image drawInRect:CGRectMake(0, 0, imageView1.frame.size.width, imageView1.frame.size.height)];    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  //設定線條終點形狀        float lengths[] = {2,2};    CGContextRef line = UIGraphicsGetCurrentContext();    CGContextSetStrokeColorWithColor(line, [UIColor blackColor].CGColor);        CGContextSetLineDash(line, 0, lengths, 2);  //畫虛線    CGContextMoveToPoint(line, 10.0, 10.0);    //開始畫線(10是指從imageView1y軸起點後的10-50 高共40)    CGContextAddLineToPoint(line, 10.0, 50.0);    CGContextStrokePath(line);        imageView1.image = UIGraphicsGetImageFromCurrentImageContext();
橫向:    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 100, 320, 20)];    [self.view addSubview:imageView1];        UIGraphicsBeginImageContext(imageView1.frame.size);   //開始畫線    [imageView1.image drawInRect:CGRectMake(0, 0, imageView1.frame.size.width, imageView1.frame.size.height)];    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  //設定線條終點形狀        float lengths[] = {10,5};    CGContextRef line = UIGraphicsGetCurrentContext();    CGContextSetStrokeColorWithColor(line, [UIColor redColor].CGColor);       CGContextSetLineDash(line, 0, lengths, 2);  //畫虛線    CGContextMoveToPoint(line, 0.0, 20.0);    //開始畫線(從X軸從0到310)    CGContextAddLineToPoint(line, 310.0, 20.0);    CGContextStrokePath(line);        imageView1.image = UIGraphicsGetImageFromCurrentImageContext();

注意:lengths的值{10,10}表示先繪製10個點,再跳過10個點,如此反覆

        如果把lengths值改為{10, 20, 10},則表示先繪製10個點,跳過20個點,繪製10個點,跳過10個點,再繪製20個點,如此反覆

 

3:去掉系統navigationBar內建底下黑邊(在viewDidLoad裡面實現)

- (void)viewDidLoad {    [super viewDidLoad];        [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];}

 

4: XCode 同一Project建立多個target

假設原來的target名字為A,我們需要建立一個target B1. 在原來的target上右鍵,選擇duplicate,Xcode會複製一個名為A copy的target對象,同時產生一個A copy-info.plist和A copy的scheme2. 改名a)對A copy target改名,可以直接單擊target來修改,改成Bb)A copy-info.plist,預設產生在程式環境根目錄,也就是A.xcodeproj的同級目錄中,如果想放到裡層(比如與A-info.plist放在同級目錄),可以先在Xcode刪除A copy-info.plist索引,然後拷貝檔案到制定目錄中,然後更名為B-info.plist,在add到project中。在Project的Build Settings中,修改Info.plist File選項為B-info.plist的目錄(相對路徑),這樣就可以看到Info頁了(就是B-info.plist),接著修改ProductName和Bundle identifier,使之成為另一個app。Prefix Header的路徑,視具體需求而定是否要修改,如果兩個target可以公用同一個Prefix Header,那麼就不需要修改這裡的路徑c)修改scheme,在調試的Stop按鈕邊上,我們可以選擇本工程中所有的target來做編譯,如果不修改,在這裡選擇出來的名字就是A copy,為了與建立的target統一起來,同樣也要修改這裡的名字。點擊scheme選擇區,然後選Manager Scheme,找到A copy,然後改成你需要的名字,比如B用duplicate的好處是,如果兩個target的相同點很多,用duplicate,就可以把相關的設定全部拷貝過來,而不需要做過多的修改產生一個新的target,一定會與原target有區別,這裡可以定義先行編譯宏,來區分兩個版本的不同代碼,先行編譯宏可以在Build Settings中Preprocessor Macros定義,比如在我們建立的target B中定義先行編譯宏MACRO,然後在代碼中通過#if defined (MACRO)//target  B需要執行的代碼#else//target A需要執行的代碼#endif來區分其他:Build Phases(各target編譯所包含的內容,需要注意的是,如果建立了target B後,再往A裡面添加資源或檔案,target B中不會自動增加這些資源,需要手動添加)1.Compile Sources需要編譯的代碼檔案2.Link Binary With Libraries編譯所依賴的庫3.Copy Bundle Resources編譯需要的資源每個target可以根據具體需要增減裡面的內容

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.