-->

2014年10月13日月曜日

UINavigationBarのtitle、backButtonのフォントを変える

まず、「AppDelegate.m」の『- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions』に、
 
    UIFont *barButtonTitleFont = [UIFont fontWithName:@"mplus-2p-light" size:13];
    UIColor *barButtonTitleColor = [UIColor whiteColor];
    [[UIBarButtonItem appearance] setTitleTextAttributes:@{UITextAttributeFont:barButtonTitleFont, UITextAttributeTextColor:barButtonTitleColor} forState:UIControlStateNormal];
を記述。これで、BackButtonのフォントが変わる

次に、NavigationControllerの『ViewDidLoad』に、
    UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 44)];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont fontWithName:@"mplus-2p-light" size:22.0f];
    label.textColor = [UIColor flatWhiteColor];
    label.text = @"タイトル";
    label.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = label;
を記述。これで、タイトルのフォントが変わる。

それはそうと、m+フォントってとても美しいよね

アプリ起動時に指定した画像を表示させる

アプリを起動した時に指定した画像を表示させる
(Twitterの公式クライアントアプリとかであるやつ)
  1. プロジェクト中にある「images.xcassets」を開いて、起動時に表示したい画像をドラッグアンドドロップで設定する。

    ちなみに、必要な画像サイズはinspectorに書いてある。


  2. 「info.plist」に「Status bar is initially hidden」 という項目を追加して、Boolean型のYESに設定する。


  3. 同じく、「View controller-based status bar appearance」という項目を追加して、Boolean型のNOに設定する。
     これで、起動時からステータスバーが表示されなくなる。


  4.  「AppDelegate.m」の-『 (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions』に、
    [NSThread sleepForTimeInterval:1.0];
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    を記述する。


    これで、起動から1秒間、設定した画像が表示される
    あとは、フェードアウトするアニメーションを追加したい・・・

2014年10月11日土曜日

インスタンスメソッドの定義方法

今更ながらObj-Cの文法まとめ
あってるかなあ?

きっちりしたインスタンス変数の定義
sampleClass.h
@interface sampleClass:NSObject
{
   NSString *_string; //インスタンス変数の定義
   double _number; //インスタンス変数の定義
}
@property (nonatomic) NSString* string; //プロパティを記述すると、getterとsetterが自動で生成される
@end
sampleClass.m
@implementation sampleClass

@synthesize string = _string; //インスタンス変数とプロパティを明示的に紐付ける

//プロパティを記述していない場合、自分でgetterとsetterを作る
- (double)number{
   return _number;
}
- (void)setNumber:(double)number{
   _number = number;
}
@end
setter/getterを自分で作る場合の利点は、setter/getter内に好きなことを記述できる
例えば、_stringをセットしたついでに、UILabel.textに_stringをセットしたり

・self.propertyの使いどころ
getter/setter/init/deallocのみ_propertyを使い、
その他はself.propertyを使う

2014年10月6日月曜日

JASidePanelControllerでサイドパネルを開くたびに呼ばれるメソッド

JASidePanelControllerを使ってみて、サイドパネルを開くたびにビューを更新しようと思ったけど、デフォルトでその機能がないみたいなのでメモ

JASidePanelController.hに
- (void)prepareShowRightPanel;
を追記

JASidePanelController.mで
- (void)_showRightPanel:(BOOL)animated bounce:(BOOL)shouldBounce {
    self.state = JASidePanelRightVisible;
    [self _loadRightPanel];
    
    [self _adjustCenterFrame];
    
    if (animated) {
        [self _animateCenterPanel:shouldBounce completion:nil];
    } else {
        self.centerPanelContainer.frame = _centerPanelRestingFrame; 
        [self styleContainer:self.centerPanelContainer animate:NO duration:0.0f];
        if (self.style == JASidePanelMultipleActive || self.pushesSidePanels) {
            [self _layoutSideContainers:NO duration:0.0f];
        }
    }
    
    if (self.style == JASidePanelSingleActive) {
        self.tapView = [[UIView alloc] init];
    }
    [self prepareShowRightPanel];//これを追加
    [self _toggleScrollsToTopForCenter:NO left:NO right:YES];
}
次に、JASidePanelControllerのサブクラスに
- (void)prepareShowRightPanel {
    NSLog(@"show right panel");
}
を記述

これで、右のサイドパネルを開くたびに
show right panel
とログが表示される

2014年9月29日月曜日

2014年9月7日日曜日

2014年6月8日日曜日

【HTMLParser】HTMLのパース

HTMLParserを使うときのメモ

#import "HTMLParser.h"でインポートして、
プロジェクトのGeneralを選択

その中のLinked Frameworks and Librariesにて、
libxml2.dylibを追加する

次は、Build SettingsのSerchPathsのHeader Search Pathsに
$(SDKROOT)/usr/include/libxml2を追加する
(行の最後に半角スペースを入れて↑をコピペ)

完成です

2014年6月6日金曜日

【HTML】テキストの画像回り込み

webページで、テキストを画像に回りこませる方法
http://www.keni-customize.net/img-mawarikomi-681/

<p><img src="hoge.jpg" class="alignleft" /></p>
<p class="mawarikomi">回りこませるテキスト</p>
<p class="clear">回り込み解除</p>


p.mawarikomi{
overflow: auto;
}

p.clear{
clear: both;
}


HTML初心者なので、htmlにスタイルを書き込む方法メモ
<div style = "overflow:auto; color:red;">hogehoge</div>



2014年5月13日火曜日

【Apache2】webページのBasic認証についてのメモ

.htaccessを有効にするためには、
httpd.confでAllowOverrideをOnにする

Ubuntuの場合は、httpd.confじゃなくて、
/etc/apache2/apache2.conf
です

2014年4月30日水曜日

【マルチスレッド】Objective Cのマルチスレッド実装方法

ObjCのマルチスレッドについてちょっと詳しくなったからメモ

1. GCDを使う
 前にも書いたけど、スレッドはGCDを使うのが楽
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{
    [self doSomething]; //別スレッド
    dispatch_sync(dispatch_get_main_queue(), ^{
        [self doSomething]; // メインスレッド
    });
});
この場合、別スレッドに重い処理を書いて、メインスレッドはUIの描画が一般的らしい
PRIORITYで優先度も設定できる
そして、インスタンスメソッドはスレッドを指定して実行することができる
[self performSelectorOnMainThread:@selector(refresh)
                        withObject:nil
                    waitUntilDone:NO];
2. NSOperationを使う
NSOperationQueue *queue = [NSOperationQueue new];
    MyOperation *operation = [MyOperation new];//NSOperationを継承したクラスを作成
    [queue addOperation:operation];
 
3. NSInvocationOperationを使う
 この場合、NSOperationの継承クラスを作らなくてもいい
NSInvocationOperation *invOperation = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(aaa) object:nil];
    [queue addOperation:invOperation];
4. とりあえずバックグラウンドに投げる
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{


        // ここに非同期でバックグラウンドに投げたい処理を書く

    });

2014年4月29日火曜日

【UICollectionView】カスタムセルをxibで作成

storyboard上でUICollectionViewを用意して、
xibで作ったUICollectionViewCellのカスタムクラスを配置する

1. file > new > file > UserInterface でviewを選択、ファイル名をmyCell.xib
 ラベルをUICollectionViewCellの上に配置する
2. 同じ名前の.hと.mファイルを作成する
3. myCell.xibのFIle's ownerのCustom ClassをmyCellに

 viewを選択して、identifierをmyCellに
 
  Custom CalssもmyCellに

myCellにプロパティを記述
myCell.h
 
#import 

@interface myCell : UICollectionViewCell

@property (strong, nonatomic) IBOutlet UILabel *cellLabel;


@end
myCell.m
 
#import "myCell.h"

@implementation myCell


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


-(void)awakeFromNib
{
    NSLog(@"bundleLoader waked");
}

@end


4. myCell.xibのFIle's ownerではなく、viewを選択して
 inspectorのoutletから用意したプロパティとxib上のラベルをつなぐ

このやりかたでないと、
 Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x6858780> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key… 

とエラーが...

5. あとはcollectionViewController.mで
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *identifier = @"myCell";
    static BOOL nibCellLoaded = NO;
    
    if(!nibCellLoaded){
        UINib *nib = [UINib nibWithNibName:@"myCell" bundle:nil];
        [collectionView registerNib:nib forCellWithReuseIdentifier:identifier];
        nibCellLoaded = YES;
    }
    
    
    myCell *cell = (OBWeather*)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    cell.backgroundColor = [UIColor greenColor];

    return cell;
}
 
 

最後に思ったけど、
クラス名とidentifierって一緒じゃない方がいいのかなあ

【iOS】Podfileの設定とエラー

Podfileの記述例:
 
platform :ios, '7.0'
pod 'LXReorderableCollectionViewFlowLayout'
pod 'MagicalRecord' 


 [!]  Unable to satisfy the following requirements: 
 - `LXReorderableCollectionViewFlowLayout (= 4.3)` required by `Podfile` 
みたいなエラーが出る場合は、上記の例みたいにiOSのバージョンを指定する必要がある


 [!]  Oh no, an error occurred.
Search for existing github issues similar to yours:
ってエラーが出る場合はこれ

$ sudo rm -rf ~/.cocoapods/repos/master
$ sudo pod setup



[参考]http://qiita.com/u651601f/items/87203d22857d3634f955

【UICollectionView】セルの並び替えをする

iOSのホーム画面みたいに、UICollectionViewのセルを並び替えるライブラリ
http://urouro.net/blog/2014/01/17/lxreorderablecollectionviewflowlayout/

いつか使えるであろう...

2014年4月25日金曜日

【iOS】メソッドのラベルを省略

Obj-Cで、引数が複数あるメソッドは通常

 - (リターン型)メソッド名:(引数型1)引数名1 ラベル:(引数型2)引数名2 ラベル:(引数型3)引数名3...

と続くが、ラベルは省略可能(推奨はされてない?)ということを知りました。
省略すると

  - (リターン型)メソッド名:(引数型1)引数名1:(引数型2)引数名2:(引数型3)引数名3...

 となります。呼び出す時は、

  [インスタンス名 メソッド名:引数1:引数2:引数3];

すごい違和感

2014年4月23日水曜日

【iOS】マルチスレッド

マルチスレッドに手をつけたのでメモ
http://blog.77jp.net/dispatch_async-copy-paste
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // バックグランドでAPIなどを実行
    });
    
    dispatch_async(dispatch_get_main_queue(), ^{
        // メインスレッドで処理をしたい内容、UIを変更など。
    });
    
    // APIなどはバックグランドで実行して、UIはメインスレッドで処理をしたい場合。
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // バックグランドでAPIなどを実行
        dispatch_async(dispatch_get_main_queue(), ^{
            // メインスレッドで処理をしたい内容、UIを変更など。
        });
    });
ちなみに今回からSyntax Highlighterを導入してみました
コードが美しい


2014年3月26日水曜日

【UITableViewCell】UITableViewCell上のUIButtonのイベントを受け取る

UITableViewCellにUIButtonを配置したけど、タップしても反応しないっていう時があります
しかし、なぜか反応するときもあります 謎です

色々調べると、解決方法はいくつかあるみたいだけど、一番簡単な方法はこれ
http://paranishian.hateblo.jp/entry/objc/ios7-tableviewcell

-(void)awakeFromNib
{
    [self.contentView setUserInteractionEnabled: NO];
}

実にスマート!

【iOS】Auto Layoutのお話

iPhone4以前とそれ以降では画面のサイズが違うから、
xibの2種類いるんじゃね?って思ってたけどそんなことなかった

xibのinspectorでauto sizingを設定すれば、レスポンシブな感じにできるんだけど、
auto sizingの設定項目がない!ってときにはこれを確認

http://dev.classmethod.jp/references/ios-7-xcode-5-auto-layout-2/


Use AutoLayoutのチェックを外すと出てきます


2014年2月20日木曜日

【cookie】webサイトからcookieを受け取る方法

cookieってなんとなく分かってたつもりだけど
詳しく知らなかった…

webサイトにPOSTして返ってきたcookieを保存したりする方法
http://www.yoheim.net/blog.php?q=20130701

cookieを返すかどうかの設定はサイト側で行えば良いんだと思う
あと、cookie使うメリットは、最初に認証してそのときに貰ったcookieを使えば、
2回目以降の認証をする必要がないってこと


「あー、cookieね、はいはい、で、なんだっけ?」
みたいな感じから少しレベルアップした気がした


2014年2月4日火曜日

リジェクト…

一回目の審査でリジェクトされました

  • 10.6: Apple and our customers place a high value on simple, refined, creative, well thought through interfaces. They take more work but are worth it. Apple sets a high bar. If your user interface is complex or less than very good it may be rejected
  • 18.2: Apps that contain user generated content that is frequently pornographic (ex "Chat Roulette" apps) will be rejected
  • 22.2: Apps that contain false, fraudulent or misleading representations will be rejected

10.6

We found the following issues with the user interface of your app:

- Did not include iOS features. For example, it would be appropriate to use native iOS buttons and iOS features other than just web views, Push Notifications, or sharing.

以下、Google翻訳
IOS機能が含まれていませんでした。たとえば、ネイティブのiOSのボタンを使用することが適切であろうとiOSは単なるウェブ景色以外の他の機能、プッシュ通知、または共有。

These examples identify types of issues discovered in your app but may not represent all such issues. It would be appropriate to thoroughly evaluate your app to address these types of issues.




[追記]
http://sarudeki.jp/arudente/2012/09/26/apple-リジェクト-(reject)まとめ一覧/

[追記]
なんか、18.2に関しては以下のサイトに載ってるやつと一緒ぽい
解決できるかなあ
https://support.tapatalk.com/threads/need-some-help-with-getting-my-app-approved.17350/
http://stackoverflow.com/questions/16456351/app-store-rejection-18-2

[追記]
こっち見たらいけそうな気がしてきた
http://neoinspire.net/archives/336#.UvCJi3l6ois

2014年1月31日金曜日

アプリ審査

土曜日に申請出してたんだけど、今日の朝起きたら
「審査してるよー」って旨のメールがきてた

しかし、また土日はさむからまだまだかかりそう

2014年1月27日月曜日

【iOSアプリ】アプリの審査待ちでそわそわしたら

以下のサイトで審査の込み具合が確認できるみたい
・Apple公式ページ
https://developer.apple.com/news/ 


・世界中のアプリ開発者から自己申告されたレビュー日数を元に平均日数を算出してくれるサービス…らしい (Qiitaより)
http://reviewtimes.shinydevelopment.com

5営業日以内に審査始まるってこと?


2014年1月26日日曜日

【スクレイピング】webサイトからデータをパクってくる

・スクレイピングするライブラリ
結局は<td class = ~~>とか<div img=~~>の~~の部分しか取って来れなくて、
タグとタグの間の文字をとれなかった
http://d.hatena.ne.jp/laiso+iphone/20120715/1342350160

・webサイトのhtmlをダウンロードして、innerhtmlを解析する
https://github.com/acoomans/WebScraper

タグとタグのデータをとる方法


HTMLParser *parser = [[HTMLParser alloc] initWithString:htmlstring error:&error];
    if (error) {
        //NSLog(@"Error: %@", error);
        return;
    } 
HTMLNode *bodyNode = [parser body];
    
    NSArray *inputNodes = [bodyNode findChildTags:@"div"];//divタグの物を全部とってくる

    item = [[NSMutableDictionary alloc]init];
    int appendCount = 0;
    
    for (HTMLNode *inputNode in inputNodes) {
        
        if([[inputNode getAttributeNamed:@"class"] isEqualToString:@"name"])
        {//そのなかでclass属性がnameの物にしぼる。
            
            homeTeam = [[NSString alloc]init]; 
            homeTeam = [inputNode contents];
            homeTeam = [homeTeam stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

            
            [item setObject:homeTeam forKey:@"home"];
            appendCount++;
        } 

HTMLParserを使って 解析する

【RSS】RSSフィードを作る

xcode5でビルドしてみたけど失敗した
役に立つか微妙
http://news.mynavi.jp/column/iphone/005/

【UIWebView】クラッシュあるある

要は、Viewが消えるときに、activityIndicatorを消してないとクラッシュするらしい
http://iapp7.blog29.fc2.com/blog-entry-100.html

こっちはdeallocのこと書いてるけど、ARCではdeallocとか意識しなくてよかった気がする
1. http://www.zero4racer.com/blog/628
2. http://www.zero4racer.com/blog/642

【アイコン作成】iOSアプリのアイコンについて

アイコンのサイズの早見表
http://dev.classmethod.jp/references/ios-device-icon-file-list-2013-9/

トースターみたいに簡単にいろんなサイズのアイコンを出してくれる
けど、申請時は1024×1024しか使ってないから、ぶっちゃけ必要かどうか分からん
http://makeappicon.com


1024×1024はGimpで作って、角を丸くするのは難しそうだったから
Icon Shaperっていうアプリを買った

【iTunes connect】入金とかの設定

http://onthehammock.com/blog/1286

銀行を指定するところで、UFJはBank of ~だから、
startedをbankにしないと出てこないという罠

【アプリ申請】一連の流れ




1.http://onthehammock.com/blog/705

2.http://onthehammock.com/blog/751

3.http://onthehammock.com/blog/778

他にちょっとした情報
http://qiita.com/koogawa@github/items/5e2ff5a0312cb1f657f8

【iAd】アプリにバナー広告をつける

iOSシミュレータだとバナーが表示されない
あと、バナーが取得できてないのに、真っ白なviewを表示してるとリジェクトされるらしい

UITableViewControllerにADBanerViewを載せるのは、このページを参考にする
http://takadayuichi.hatenablog.com/entry/20130106/1357463693

LandScapeモードに対応させるやり方(ほんとに出来るかは調べてない)
http://maccle.com/develop-ios-app/how-to-implement-iad/
https://sites.google.com/site/propicaudio/sample-code/iad-test