2011. 11. 21. 18:13

특정 문자로 문자열 쪼개기

뭐, 유식한 말로 tokenize 라던가 split 라고 하기도 하지만,
역시 쪼개는게 맛이..( -_-);;

자주 써먹었는데 맨날까먹고 다시 찾아보고 해서;;
그래서 써 놓는다.

아이폰 쪽은 뭐랄까 전체적인 이름들이 길고 장황해서리;;;

NSString *string = @"oop:ack:bork:greeble:ponies";
NSArray *chunks = [string componentsSeparatedByString: @":"];

뭐 이정도면 대략 알듯 6^^ 
2011. 11. 21. 18:08

UINavigationItem 제목부분 가운데 정렬하기

팔자에도 없는 아이폰 프로그램을 하게된 관계로,
이것도 인터넷에서 줒어온 코드를 좀 변형한것.

인터넷의 코드는 중앙정렬을 했는데,
이건  좌측정렬에 뒤에 작은 글씨로 다른 글씨를 붙였음
결국 UIView 하나 올리고 그거 이용하게 만들었다능;;

일단 카테고리를 사용하며,
아직은 실력이 없어서 주로 사용하는 헤더 파일 하나 안에 아래 코드를 다 밀어 넣으니 알아서 잘 돌아갔음

아래는 코드 전체 -_-);

@interface UINavigationItem (UINavigationItemCategory)

- (void)setTitle:(NSString *)title;

@end


@implementation UINavigationItem (UINavigationItemCategory)


- (void)setTitle:(NSString *)title {

//UIFont *fnt = [UIFont systemFontOfSize:[UIFont boldSystemFontOfSize:20.0f]];

UIFont *fnt = [UIFont boldSystemFontOfSize:20.0f];

CGSize lblSize = [title sizeWithFont:fnt];

UIFont *fntSmall = [UIFont systemFontOfSize:[UIFont smallSystemFontSize]];

UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, lblSize.width, 30)] autorelease];

UILabel *lbl2 =  [[[UILabel alloc] initWithFrame:CGRectMake(lblSize.width, 0, 320 - lblSize.width, 30)] autorelease];

    label.backgroundColor = [UIColor clearColor];

    label.textColor = RGB(255, 255, 255);

label.font = fnt;

lbl2.backgroundColor = [UIColor clearColor];

lbl2.font = fntSmall;

    lbl2.textColor = RGB(255,255,255);

lbl2.text = @"Test";

label.text = title;

    UIView *tmpView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];

[tmpView addSubview:label];

[tmpView addSubview:lbl2];

    self.titleView = tmpView;

2011. 7. 26. 09:57

2진수->10진수, 10진수->2진수 함수


이진수를 십진수로 변환하는 함수
문자열로 된 이진수 스트링을 받아서 숫자로 돌려줌
어디선가 줒어온 소스 변경 -_-);

+(NSInteger)Bin2Dec:(NSString *)strBin {
 unichar aChar;
 int value = 0;
 int index;
 for (index = 0; index<[strBin length]; index++)
 {
  aChar = [strBin characterAtIndex: index];
  if (aChar == '1')
   value += 1;
  if (index+1 < [strBin length])
   value = value<<1;
 }
 return value;
}


십진수를 이진수로 변환하는 함수
숫자로 된 십진수를 받아서 이진수모양의 스트링으로 변경
아래쪽에 리턴이 없어서 뭔가 경고가 나오긴 하는데 괜찮겠지 뭐;; ( -_-);

+(NSString *)Dec2Bin:(NSInteger)iDec {
 if (iDec == 1 || iDec == 0)
  return [NSString stringWithFormat:@"%d", iDec];

 [NSString stringWithFormat:@"%@%d", [self Dec2Bin:iDec / 2], iDec % 2];
}