スキップしてメイン コンテンツに移動

投稿

5月, 2013の投稿を表示しています

block1

double (^g)( double , double ); g = ^( double m, double n) { return a + b; }; // .. later g = ^( double x, double y) { return x * y; }; // g reassigned to point to a new block; same type, so no problem // but not: // g = ^(int x) { return x + 1; }; // types are different! The literal on the right has type int(^)(int), not double(^) (double, double)! double (^h)( double , double ) = g; // no problem here! h has the correct type and can be made to point to the same block as g // compare with: int i = 10, j = 11; // declaring a coupling of integers int *ptrToInt; // declaring a pointer to integers ptrToInt = &i; // ptrToInt points to i // later... ptrToInt = &l // ptrToInt now points to j float f = 3.14; // ptrToInt = &f; // types are different! technically can be done, but compiler will warn you of the type difference. And typically you don't want to do this! int *anotherPtrToInt; anotherPtrToInt = ptrToInt; // both pointers p...

uicollectionview

Take a look at these components one-by-one: UICollectionView  – the main view in which the content is displayed, similar to a UITableView. Note that it doesn’t necessarily have to take up the entire space inside the view controller – in the screenshot above, there’s some space above the collection view where the user can search for a term. UICollectionViewCell  – similartoaUITableViewCellinUITableView. Thesecells make up the content of the view and are added as subviews to the UICollectionView. Cells can either be created programmatically, inside Interface Builder, or via a combination of the two methods. Supplementary Views  – if you have extra information you need to display that shouldn’t be in the cells but still somewhere within the UICollectionView, you should use supplementary views. These are commonly used for headers or footers of sections. Decoration View  – if you want to add some extra views to enhance the visual appearance of the UICollectionView ...

uiscrollview pagecontrol

#import "pageControlViewController.h" @interface pageControlViewController () @end @implementation pageControlViewController @synthesize scrollView; @synthesize pageControl; const CGFloat kScrollObjHeight = 130.0 ; //( ※ 1)1page の高さ const CGFloat kScrollObjWidth  = 320.0 ; //( ※ 2)1page の幅 const NSUInteger kNumImages    = 3 ;    //( ※ 3) 総 page 数 //ScrollView の設定 - ( void )layoutScrollImages {     UIImageView *view = nil ;     NSArray *subviews = [ scrollView subviews ];          CGFloat curXLoc = 0 ;     for (view in subviews)     {         if ([view isKindOfClass :[ UIImageView class ]] && view. tag > 0 )         {             CGRect frame = view. frame ;             frame. origin = CGPointMake (curXLoc, 0 ); ...

fmodf

C言語の標準ライブラリfmodfのリファレンスです。 fmodf <fmodf> 概要 x/yの浮動小数点剰余を計算する(float)。 ヘッダ #include <math.h> I/F float fmodf(float x, float y); 戻り値 ある整数nに対するx - nyの値。 詳細 fmodf関数は、x/yの浮動小数点剰余を計算する。yが0以外の場合、計算結果は、ある整数nに対するx-nyの値である。その値は、xと同じ符号で、yの絶対値より小さい絶対値をもつ。yが0の場合、結果を0とするか、定義域エラー発生とするかは処理系定義である。

Objective-C/基本構文

Objective-C/基本構文 if文、for文、switch文、while文、do-while文の構文です。 書き方を忘れた時にも便利です。 if構文 ifは条件に合致するかしないかを判定する処理です。 // if構文 if(条件){ // 条件=YESの場合の処理 } // if~else構文 if(条件){ // 条件=YESの場合の処理 }else{ // 条件=NOの場合の処理 } // if~else if構文 if(条件1){ // 条件1=YESの場合の処理 }else if(条件2){ // 条件2=YESの場合の処理 }else{ // 条件1、条件2いずれもNOの場合の処理 } // 三項演算子構文 (条件)?<条件=YESの場合の処理>:<条件=NOの場合の処理>; ※上記「if~else構文」と同じ処理になります。 // 三項演算子例文 // aとbが同じなら「おなじ」違う時は「ちがう」を返す。 NSString *str = (a==b)?@"おなじ":@"ちがう"; for構文 forは指定された回数だけ処理をループ実行します。 // for構文 for(変数初期値; ループ回数; 変数増分){ // 処理 } // for例文 // 例:iを0から99まで100ループさせる for(int i=0; i<100; i+){ // 処理 } for文には高速列挙というリスト型の件数分ループ処理を行うということもできます。 // 高速列挙構文 for(取り出す変数の型 取り出す変数名 in コレクションクラス){ // 処理 } // 高速列挙例文 // 例:変数arrayに格納されているデータを変数strとして取り出してNSLogに出力する (※arrayはNSArray型、格納されているデータはNSString型とする) for(NSString *str in array){ NSLog(str); } switch構文 switchは与えられた値から処理を選択する判定処理です。 判定はbreakで抜けない限り、caseの上...

CGRect、CGPoint、CGSize

サイズ指定 UIViewやそのサブクラスでサイズや位置を指定するにはCGRect、CGPoint、CGSizeクラスを使用します。 CGRect CGRectは、対象オブジェクトの位置とサイズの両方を管理するクラスです。 生成するには、CGRectMakeを使用し、引数には「位置x, 位置y, 幅, 高さ」の順で指定します。 // CGRectの生成 CGRect rect = CGRectMake(0, 0, 100, 80); // 位置x、位置y、幅、高さ全て0のCGRectを生成する CGRect rect = CGRectZero; CGRectから値を取得するには以下のプロパティにて取得できます。 【CGRectの主要プロパティ】 プロパティ/型 説明 origin.x (float) 位置のX座標を取得する (例)コントローラ(label)のX座標を取得する  float labelx = label.frame.origin.x; origin.y (float) 位置のY座標を取得する (例)コントローラ(label)のY座標を取得する  float labely = label.frame.origin.y; size.width (float) 幅を取得する (例)コントローラ(label)の幅を取得する  float labelw = label.frame.size.width; size.height (float) 高さを取得する (例)コントローラ(label)の高さを取得する  float labelh = label.frame.size.height; // UILabelを用いた例文 UILabel *label = [[[UILabel alloc] init] autorelease]; label.frame = CGRectMake(10, 10, 100, 50); CGPoint CGPointは、対象オブジェクトの位置を管理するクラスです。 生成するには、CGPointMakeを使用し、引数には「位置x, 位置y」の順で指定します。 // CGPointの生成 CGPoint point = CGPointMake(200, 300);...

add searchbar for UICollectionView

- ( void ) viewDidLoad { [ super viewDidLoad ]; self . searchBar = [[ UISearchBar alloc ] initWithFrame : CGRectMake ( 0 , 0 , CGRectGetWidth ( self . collectionView . frame ), 44 )]; self . searchBar . autocorrectionType = UITextAutocorrectionTypeNo ; self . searchBar . delegate = self ; [ self . collectionView addSubview : self . searchBar ]; [ self . collectionView setContentOffset : CGPointMake ( 0 , 44 )]; } - ( void ) viewWillAppear :( BOOL ) animated { // to show search bar [ self . collectionView setContentOffset : CGPointMake ( 0 , 0 )]; // to hide search bar [ self . collectionView setContentOffset : CGPointMake ( 0 , 44 )]; } -( void ) searchBarTextDidBeginEditing :( UISearchBar *) searchBar { [ searchBar setShowsCancelButton : YES animated : YES ]; } -( void ) searchBarCancelButtonClicked :( UISearchBar *) searchBar { [ searchBar setText :@ "" ]; [ searchBar setShowsCancelB...