スポンサーサイト

上記の広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書く事で広告が消せます。

UITextFieldの入力前の値

UITextFieldに入力を促すグレーの文字とかよくみかけますよね。
あれの設定は「setPlaceholder」でできます。
知ってました?知ってますよね、ごめんなさい;

iPhoneのキーボードサイズ

iPhoneのSWキーボードのサイズは以下が詳しい。
iPhoneアプリケーションプログラミングガイド

keyboard_size

まあ、うまく動くようになってきたら、固定値から
下記みたいにきちんとキーボードサイズを取得してやるのがよいのかもです。

// キーボードのサイズを取得する
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;

UITextViewの文字数カウント

UITextViewに入力された文字数をカウントする。
UITextViewDelegateをViewControllerに宣言しておく。

@interface projectViewController : UIViewController <UITextViewDelegate>
IBOutlet UILabel *letterCountLabel;
...


んで、- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text を下記のような感じで使う。
letterCountLabelは文字数を表示するためのアウトレット。
letterCountLabelに文字数を表示し、100文字をオーバーしたら文字を赤くする。

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
int textcount=[textView.text length] + [text length] - range.length;
if (textcount>100) {
letterCountLabel.textColor=[UIColor redColor];
}else{
letterCountLabel.textColor=[UIColor whiteColor];
}
letterCountLabel.text=[NSString stringWithFormat:@"%d",textcount];
return YES;
}


これでTwitterアプリなんかの文字数カウントに対応できるね!!

iPhoneSDK開発のレシピ

iPhoneSDK開発のレシピiPhoneSDK開発のレシピ
(2010/03)
高山 恭介広部 一弥

商品詳細を見る
一言で感想を言うと、買ってよかった!
ひとつ真面目にアプリを開発しようと思うと、あれってどうやればいいんだろうという場面に遭遇することって多い。そんなときに、この本が網羅しているレシピがかなりヒットする確率が高く、かゆいところに手がとどく一冊になっていると思う。
一つ目の試作アプリを作り終えて、アプリの完成度を高めようと考えている人や、次のアプリの構想を練るときなんかに使えると思う。
意外とネットとかにない情報やTipsなんかもあってGood!

このリンクに目次があるので、一つでも自分がやりたいことがあれば購入の価値アリです。
http://www.shuwasystem.co.jp/products/7980html/2579.html

UITableViewの基本

UITableViewを初めて使ってみた。もういきなり挫折しそうなくらい意味不明。。。
結論としてはInterface BuilderからはUITableViewを置くところまでしかできず、
何を表示させるかは別に設定する必要があるようで。

UITableView

IBでUITableViewを設置しStyleはGroupedを設定。
あとは以下コードをViewControllerにおけば動くと思います。
(arraySectionとかの配列はヘッダで宣言してます。)

//ビュー読み込み時の初期化処理
- (void)viewDidLoad {
arraySection = [[NSArray alloc] initWithObjects:@"Account", @"Canvas",nil];
arrayCell0=[[NSArray alloc] initWithObjects:@"fumi2_nagai",nil];
arrayCell1=[[NSArray alloc] initWithObjects:@"Blur",@"R",@"G",@"B",nil];
[super viewDidLoad];
}

//セクション数の設定
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
//セクションタイトルの設定
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [arraySection objectAtIndex:section];
}
//各セクションのセル数の設定
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int sections=0;
switch (section) {
case 0:
sections= 1;
break;
case 1:
sections= 4;
break;
default:
break;
}
return sections;
}

//セルタイトルの設定
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell
switch (indexPath.section) {
case 0:
cell.textLabel.text = [arrayCell0 objectAtIndex:indexPath.row];
break;
case 1:
cell.textLabel.text = [arrayCell1 objectAtIndex:indexPath.row];
break;
default:
break;
}
return cell;
}


もっとスマートなやり方があれば、教えてください。。。

 | HOME |  »

Calendar

« | 2012-05 | »
S M T W T F S
- - 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31 - -

Monthly

Categories

Recent Entries

Recent Comments

Recent Trackbacks

Appendix

ふみふみさん。

ふみふみさん。

iPhoneを売っている会社で働いているけど、iPhoneに関わっていない人。つまり一般人です。

FC2ブログ(blog)