CustomNavigationController

iphone | 2010/05/25 22:36 | 사니아신
0. 목적
title 영역에 background image 넣고싶다.

1. 구현


@interface CustomNavigationController : UINavigationController {

}

@end


#import "CustomNavigationController.h"


@implementation UINavigationBar(background)

- (void)drawRect:(CGRect)rect {

[super drawRect:rect];

UIImage* image = [UIImage imageNamed: @"title_bg.png"];

[image drawInRect:CGRectMake(0,0,self.frame.size.width,self.frame.size.height)];   

}

@end


@implementation CustomNavigationController

@end

AR class diagram

iphone | 2010/05/04 02:18 | 사니아신
0. 설계

1. 결과물


iphone logger

iphone | 2010/04/23 02:06 | 사니아신
0. 목적
simply iphone logger

1. 참고
http://stackoverflow.com/questions/202299/logging-to-a-file-on-the-iphone
http://www.iphonedevsdk.com/forum/iphone-sdk-development/8162-debugging-tip-nslog.html

2. 조건
configuration=debug 일때만 로그를 남긴다.

3. 구현

3-1. macro setting
preprocessor macro 에 설정




3-2. Logger.h , m

#ifdef DEBUG

#define Log(s, ...) NSLog(s, ##__VA_ARGS__)

#else

#define Log(s, ...)

#endif


@interface Logger : NSObject {


}

+ (NSString*)path;

+ (void)write:(NSString*)str;

+ (NSString*)read;

+ (void)remove;


@end


#import "Logger.h"


@implementation Logger


+ (NSString*)path{

NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *path = [docsDirectory stringByAppendingPathComponent:@"log.txt"];

return path;

}


+ (void)write:(NSString*)str{

#ifdef DEBUG

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateFormat:@"HH.mm.ss"];

NSString* log = [NSString stringWithFormat:@"%@-%@\n\r" , [dateFormatter stringFromDate:[NSDate date]] , str];

[dateFormatter release];

NSString* storeLog = [Logger read] ? [Logger read] : @"";

NSData *dataToWrite = [[NSString stringWithString:[storeLog stringByAppendingString:log]] dataUsingEncoding:NSUTF8StringEncoding];

[dataToWrite writeToFile:[Logger path] atomically:YES];

#endif

}


+ (NSString*)read{

return [[[NSString alloc] initWithContentsOfFile:[Logger path]] autorelease];  

}


+ (void)remove{

NSFileManager *fileManager = [NSFileManager defaultManager];

if ([fileManager fileExistsAtPath:[Logger path]]){

[fileManager removeItemAtPath:[Logger path] error:NULL];

}

[fileManager release];

}


@end


3-3 delegate 에 추가

#ifdef DEBUG

#if TARGET_IPHONE_SIMULATOR == 0

Log([Logger read]);

[Logger remove];

#endif

#endif




iphone simulator & device 구분하기

iphone | 2010/04/23 01:11 | 사니아신

#if TARGET_IPHONE_SIMULATOR == 1

NSLog(@"simulator");

#else

NSLog(@"device");

#endif

custom UIPageControl

iphone | 2010/04/19 15:19 | 사니아신

0. 목적 및 동기

요구되는 디자인이 기본 UIPageControl의 UI를 사용하지 않는다.

그래서 CustomPageControl 필요해졌다.

UI control구조에 익숙한 사람이라면 control 들은

subcontrol 들의 조합으로 이루어 졌다는 사실을 예상할 수 있을것이다.

UIPageControl 도 마찬가지로 점들을 이루는 UIImageView

subcontrol 존재한다.


1. 코드


@interface CustomPageControl : UIPageControl {

}


@end


#import "CustomPageControl.h"

#define kOffImage [UIImage imageNamed:@"offImage.png"]

#define kOnImage [UIImage imageNamed:@ "onImage.png"]


@implementation CustomPageControl


- ( void)layoutSubviews{

[super layoutSubviews];

UIImage* image = kOffImage;

for (UIImageView* view in self .subviews){

CGRect frame = view.frame;

frame.size = image.size ;

view.frame = frame;

view.image = image;

}

}


- (void)setCurrentPage:(int)index{

   [super setCurrentPage:index];

for (int i = 0 ; i < [self.subviews count] ; i++){

UIImageView* view = [self.subviews objectAtIndex:i];

view.image = (i == index) ? kOnImage : kOffImage ;

}

}


@end