Skip to content

Instantly share code, notes, and snippets.

@ttsubono
ttsubono / gist:2969782
Created June 22, 2012 02:07
NavigationBarをbarStyleで黒色にする
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.tintColor = nil;
@ttsubono
ttsubono / gist:2969820
Created June 22, 2012 02:16
NavigationBarをtintColorで黒色にする
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
@ttsubono
ttsubono / gist:2969830
Created June 22, 2012 02:17
NavigationBarを黒色半透明にする
self.navigationController.navigationBar.tintColor = nil;
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.backgroundColor = nil;
@ttsubono
ttsubono / gist:2969889
Created June 22, 2012 02:45
iOS4でNavigationBar上のボタン色をダイナミックに変える
for (UIView *view in self.navigationController.navigationBar.subviews) {
if ([[[view class] description] isEqualToString:@"UINavigationButton"]) {
[(UINavigationButton *)view setTintColor:newColor];
}
}
@ttsubono
ttsubono / gist:2970887
Created June 22, 2012 07:01
self.viewをフリップ(水平回転)して別のビューに切り替える(&戻す)
#define FLIP_ANIMATION_DURATION 0.5
static BOOL flipFromLeft = YES;
// secondViewを作る
if (flipFromLeft) {
secondView = ... // Flipして表示したいsecondViewにインスタンス割り当て(secondViewというメンバー変数があること)
}
// self.view -> secondViewへFlipして切り替える
[UIView transitionFromView:(flipFromLeft ? self.view : secondView)
toView:(flipFromLeft ? secondView : self.view)
duration:FLIP_ANIMATION_DURATION
@ttsubono
ttsubono / gist:2971304
Created June 22, 2012 08:24
NavigationBarに置いたUISegmentedControlのインスタンスを水平回転
- (void)addNavigationBarButton {
// 黒色のNavigationBarに黒色のボタンの場合
// setmentedControlObjectがメンバー変数としてあること
NSArray *controlItems = [NSArray arrayWithObjects:@"BBB", nil];
segmentedControlObject = [[UISegmentedControl alloc] initWithItems:controlItems];
segmentedControlObject.momentary = YES;
segmentedControlObject.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControlObject.tintColor = [UIColor darkGrayColor];
[segmentedControlObject addTarget:self action:@selector(flipNavigationBarButton) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:segmentedControlObject];
@ttsubono
ttsubono / gist:2988074
Created June 25, 2012 11:28
MKMapViewの地図をピン(annotation)が全て表示される大きさに調整する
//
// initでannotationクラスのcoordinateプロパティにINVALID_COORDINATEをセットしておき、
// coordinateプロパティがまだセットされていない状態であることを示す。
//
// if (CLLocationCoordinate2DIsValid(coordinate))で検証する
//
#define INVALID_LOCATION_DEGREE -1000
#define INVALID_COORDINATE CLLocationCoordinate2DMake(INVALID_LOCATION_DEGREE, INVALID_LOCATION_DEGREE)
// 最低限の地図の大きさ
#define MINIMUM_MAP_SPAN MKCoordinateSpanMake(0.002, 0.002)
@ttsubono
ttsubono / gist:2988138
Created June 25, 2012 11:46
JsonFrameworkで取って来た値をプロパティにセット
// なんか無駄な処理入ってる気がするが・・・、一応残しておく
#import "JSON.h" //JsonFramework
// JSONがNSDictionaryを持つ配列の場合
- (void)something {
id *jsonResult = [result JSONValue];
if (![jsonResult isKindOfClass:[NSArray class]]) return;
NSArray jsonArray = jsonResult;
for (id dic in jsonArray) {
[self setDistanceWithIdType:[[(NSDictionary *)dic objectForKey:@"firstKey"] objectForKey:@"secondKey"]];
@ttsubono
ttsubono / gist:3030839
Created July 2, 2012 03:32
NSStringがnil, 空文字でYESを返す
// NSStringについてはnullとnilと空文字""を判定しないといけない。
// [NSNull null]はシングルトンなのでisKindOfClass:[NSNull class]を使わずとも==[NSNull null]で判定可能。
// nilと空文字については、length==0でどちらも判別できる。
//
// (self == (id)[NSNull null] || self.length == 0)
//
// カテゴリで定義して
// NSString+MyCategory.h
@interface NSString (MyCategory)
@ttsubono
ttsubono / gist:3037036
Created July 3, 2012 01:55
ボタンの背景色をプログラムで変える方法 Changing the background color of UIButton without a image file
/** 使い方 sample usage */
#define BUTTON_RADIUS 10.0f
#define BUTTON_BORDER_WIDTH 1.0f
NSString *title = @"something";
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = rect;
[button setTitle:title forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor colorWithWhite:0.8 alpha:0.5] forState:UIControlStateNormal radius:BUTTON_RADIUS];