Posted
Filed under iphone
요즘 이미지 가지고 작업할 일이 많아져서 많이 사용하는 클래스 중 하나인 UIImage에 관한 내용이다.
외부 이미지 파일을 가져다 쓰기 위해 UIImage의 static메소드인 [UIImage imageNamed:(NSString*)name]; 을 사용하면 매우 편리하다. 하지만 이 함수는 사용하지 않는것이 좋다.
이 스태틱함수는 UIImage의 포인터를 바로 리턴해 우리가 alloc해줄 필요가 없는 동시에 release해줄 수도 없다.
그래서 데스크톱이나 노트북같이 메모리가 많지 않은 아이폰에서는 메모리 낭비가 생길 수 있다.
그래서 다소 불편하더라도 우리가 직접 alloc 해주고 full path를 명시해줘야 하는 멤버함수인 initWithContentOfFile을 이용해서 이미지를 불러오도록 하자.
아래와 같이 사용하면 된다.
[원문 : http://chirow.tistory.com/206]

//외부 이미지 불러 오기
[[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/filename.png", [[NSBundle mainBundle] bundlePath], i]];

간단한 방법으로 웹의 데이터를 긁어올 수 있습니다.
아래의 방법은 이미지가 아닌 다른 파일들에도 유효합니다.
NSString *stringURL = @"http://naver.com/image1"; //존재하지 않는 URL 입니다만...
NSURL *url = [NSURL urlWithString:stringURL];
NSData *data = [NSData dataWithContentOfURL:url];
UIImage *image = [UIImage imageWithContentData:data];
// 위와 같이 하는게 가장 간단하더군요....
UIImage *image = [UIImage imageWithContentOfURL:url];
로 하셔도 됩니다.
2011/06/20 22:44 2011/06/20 22:44
Posted
Filed under iphone

[self.navigationController popViewControllerAnimated:YES];
self는 NaviationController 입니다.

2011/06/16 18:16 2011/06/16 18:16
Posted
Filed under iphone
// In the MyClassWithStaticArray.h
+ (NSMutableArray *) myStaticNSMutableArray;

// In the MyClassWithStaticArray.m
static NSMutableArray * myStaticNSMutableArray = nil;

+(NSMutableArray *) myStaticNSMutableArray
{
    @synchronized(myStaticNSMutableArray)
{
        if (myStaticNSMutableArray == nil)
            myStaticNSMutableArray = [[NSMutableArray alloc] init];

        return myStaticNSMutableArray;
    }

return nil;
}

// Access the class array
NSMutableArray *referenceToStaticArray = [MyClassWithStaticArray
myStaticNSMutableArray];
2011/06/15 19:20 2011/06/15 19:20
Posted
Filed under iphone
1. 두 개의 문자열을 새로운 문자열로..

NSString *string1 = @"This is";

NSString *string2 = @" a test.";

NSString *string3 = [string1 stringByAppendingString:string2];

// 이제 string3 @"This is a test."  string1 string2 변하지 않는다.

2. 기존 문자열에 새로운 문자열 할당하기...

NSString *string1 = @"This is";

NSString *string2 = @" a test.";

string1 = [string1 stringByAppendingString:string2];

// 이제 string1 @"This is a test."

3. 만약 NSMutableString을 사용한다면, 간단히 appendString: 메소드를 사용할 수 있다.

NSMutableString *string1 = @"This is";

NSString *string2 = @" a test.";

[string1 appendString:string2];

// 이제 string1 @"This is a test."

2011/06/13 19:52 2011/06/13 19:52
Posted
Filed under iphone

네비게이션 바 자체에 폰트를 지정하거나 글씨의 크기를 지정하는 방법이 있는 것 같지는 않다.

하지만 여러가지 방법을 이용해서 폰트의 지정 및 글씨의 크기를 변경해 사용할 수 있다.

직접 사용해본 코드로 잘 동작하는 것을 확인할 수 있었다.

        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont fontWithName:@"Helvetica-Bold" size: 15.0];
        // Optional - label.text = @"NavLabel";
        [label setBackgroundColor:[UIColor clearColor]];
        [label setTextColor:[UIColor whiteColor]];
        [label setText:@"원하는 타이틀을 지정하세요."];
        [label sizeToFit];
        [self.navigationController.navigationBar.topItem setTitleView:label];
        [label release];

또 아래와 같이 하면 메인 타이틀 하위에 subtitle 을 넣는 효과까지 낼 수 있다.

( 사실 레이블을 두개 붙이는 것이지만..)

- (void)SetNavigationTitle:(NSString*)title subtitle:(NSString*)subTitle
{
        if (subtitle == nil) {
                self.navigationItem.titleView = nil;
                self.navigationItem.title = title;
                return;
        }

        // set the default title anyway, so the next view controllers will have the correct text on their "back" button
        self.navigationItem.title = title;
     
        #define LEFT_OFFSET 15
     
        // Replace titleView
        CGRect headerTitleSubtitleFrame = CGRectMake(LEFT_OFFSET, 0, 200, 44);   
        UIView* _headerTitleSubtitleView = [[UILabel alloc] initWithFrame:headerTitleSubtitleFrame];
        _headerTitleSubtitleView.backgroundColor = [UIColor clearColor];
        _headerTitleSubtitleView.autoresizesSubviews = YES;
     
        CGRect titleFrame = CGRectMake(LEFT_OFFSET, 2, 160, 24);   
        UILabel *titleView = [[UILabel alloc] initWithFrame:titleFrame];
        titleView.backgroundColor = [UIColor clearColor];
        titleView.font = [UIFont boldSystemFontOfSize:20];
        titleView.textAlignment = UITextAlignmentCenter;
        titleView.textColor = [UIColor whiteColor];
        titleView.shadowColor = [UIColor darkGrayColor];
        titleView.shadowOffset = CGSizeMake(0, -1);
        titleView.text = title;
        titleView.adjustsFontSizeToFitWidth = YES;
        [_headerTitleSubtitleView addSubview:titleView];
        [titleView release];
     
        CGRect subtitleFrame = CGRectMake(LEFT_OFFSET, 24, 160, 44-24); 
        UILabel *subtitleView = [[UILabel alloc] initWithFrame:subtitleFrame];
        subtitleView.backgroundColor = [UIColor clearColor];
        subtitleView.font = [UIFont boldSystemFontOfSize:13];
        subtitleView.textAlignment = UITextAlignmentCenter;
        subtitleView.textColor = [UIColor whiteColor];
        subtitleView.shadowColor = [UIColor darkGrayColor];
        subtitleView.shadowOffset = CGSizeMake(0, -1);
        subtitleView.text = subTitle;
        subtitleView.adjustsFontSizeToFitWidth = YES;
        [_headerTitleSubtitleView addSubview:subtitleView];
        [subtitleView release];
     
        self.navigationItem.titleView = _headerTitleSubtitleView;
        [_headerTitleSubtitleView release];
}

2011/06/13 14:21 2011/06/13 14:21
Posted
Filed under iphone

 

단축키

기능

Cmd+` (틸트)

 

Opt+Page up (Page down)

 

Cmd+Shift+E


Cmd+[


Cmd+]


Tab (Return 또는 →)


Esc


Ctrl+. (dot)


Shift+Ctrl+. (dot)


Ctrl+/


Cmd+/


Cmd+Ctrl+S


Ctrl+F


Ctrl+B


Ctrl+P


Ctrl+N


Ctrl+A (Cmd+←)


Ctrl+E (Cmd+→)


Ctrl+T


Ctrl+D


Ctrl+K


Cmd+Del (Cmd+Backspace)

 

Ctrl+Del (Ctrl+Backspace)


Ctrl+L


Cmd+Opt+D


Cmd+Opt+↑


Cmd+Opt+← (또는 →)


Cmd+D


Opt+더블클릭


Cmd+Shift+R


Ctrl+Cmd+Opt+R


Cmd+R

 

Cmd+Opt+R


Cmd+Y


Shift+Cmd+P


Shift+Cmd+O


Shift+Cmd+I


Shift+Cmd+T

더블클릭으로 분활된 창의 전환(Mac 기본 단축키)

 

커서와 함께 페이지 이동. (Page up/down은 커서가 같이 이동하지 않음)

 

에디터를 확장한다.


코드 블록을 왼쪽으로 쉬프트한다.


코드 블록을 오른쪽으로 쉬프트한다.


코드를 완성한다.


자동 완성 코드 목록을 보여준다. (변수, 메서드, 클래스 등)


코드 완성에서 알맞은 다음 코드를 보여준다.


코드 완성에서 알맞은 이전 코드를 보여준다.


코드 완성에서 다음 입력 영역으로 이동한다.


선택 영역을 주석 처리/해제


스냅 샷을 만든다.


커서를 앞으로 이동한다.


커서를 뒤로 이동한다.


커서를 이전 라인으로 이동한다.


커서를 다음라인으로 이동한다.


커서를 라인의 시작으로 이동한다.


커서를 라인의 끝으로 이동한다.


커서에 인접한 문자를 바꾼다.


커서에 인접한 문자를 지운다.


라인을 지운다.


커서가 있는 라인에서 커서 뒷(앞)부분을 모두 지운다.

 

커서가 있는 위치에서 가까운 뒷(앞)블락을 지운다.(보통 단어 단위)


커서를 텍스트 에디터의 가운데로 보낸다.


창을 열어 보여준다.


연결된 파일을 연다. (.h / .m 이동)

 

이전(이후) 수정 위치/파일로 이동


북마크를 추가한다.


문서를 찾는다. (요약으로 보여주며 책모양 클릭하면 문서로 이동, h는 헤더로)


콘솔창 열기/닫기


콘솔창 화면 지우기


빌드 후 바로 실행

 

이전 빌드 된 결과 실행


디버거로 프로그램을 실행한다.


(디버거에서) 계속 한다.


다음 스텝으로 넘어간다.


스텝 안으로 넘어간다.


스텝 밖으로 넘어간다.

 

저작자 표시
2011/06/09 07:07 2011/06/09 07:07
Posted
Filed under iphone
// UILabel 생성하기
UILabel *aLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 40, 20)];
// label에 태그 넣기
aLabel.tag = 1;
// 글자쓰기
aLabel.text = @"Hello World";
// 라벨을 뷰에 올리기
[self.view addSubview:aLabel];


하위에 있는 뷰 모두 지우기 1

// With some valid UIView *view:
for(UIView *subview in [self.view subviews])
{
    [subview removeFromSuperview];
}

하위에 있는 뷰 모두 지우기 2
while ([self.view.subviews count] > 0)
{
    [[[self.view subviews] objectAtIndex:0] removeFromSuperview];
}

지정한 태그의 subview 지우기
[[self.view viewWithTag:1] removeFromSuperview];

지정 태그 이외의 subview 지우기
for (UIView *subview in [self.view subviews])
{
    if (subview.tag != 1) {
        [subview removeFromSuperview];
    }
}





특정 클래스의 subview 지우기
for(UIView *subview in [self.view subviews])
{
    if([subview isKindOfClass:[UILabel class]])
    {
        [subview removeFromSuperview];
    }
}




 
if (self.blueViewController.view.superview == nil)
이 문장은 blueViewController가 슈퍼뷰의 멤버에 포함되어 있는가를 검사할 떄 사용합니다.
위와 같이 nil이라면 포함되어 있지 않다는 의미입니다.
이것은 실제로 아직 메모리에 없을 수도 있고, 메모리에 있지만 슈퍼뷰에 포함되지 않고 있을 수도 있습니다.
즉, [self.view insertSubview:blueController.view atIndex:0]; 이 문장에 의해 메인 즉 self의 서브 뷰로 등록되지 않았을 경우에 해당됩니다.
위 구문이 실행되면 메인뷰의 서브뷰로 등록되고 atIndex가 0이기 때문에 가장 앞에 표시되어 보이게 될 것입니다. 반대로 메인뷰에서 제거하려면 아래와 같이 합니다.

[blueViewController.view removeFromSuperview];

위 코드는 blueViewController를 슈퍼뷰에서 제거하게 되어 더이상 화면에 나타나지 않게 됩니다.

이상태에서는 화면 표시만되지 않을 뿐 여전히 blueViewController는 메모리에 남아있습니다.

메모리에서 제거하려면 self.blueViewController = nil;를 사용하면 됩니다.













2011/06/09 06:37 2011/06/09 06:37
Posted
Filed under iphone

/ 메소드

    - (void) handleTimer: (NSTimer *) timer

    {

      // 수행 작업 

    }

 // 타이머 생성

    NSTimer *timer;

    timer = [NSTimer scheduledTimerWithTimeInterval: 0.03f target: self selector: @selector(handleTimer:)

  userInfo: nil repeats: YES];

// 타이머 해제

   [tmier invalidate];



출처 : http://www.howapp.com/6389

2011/06/09 04:34 2011/06/09 04:34
Posted
Filed under iphone
objective-c 에서 cString을 사용 하면 warning  발생 합니다.
컴파일은 되지만 개발자 입장에서 여간 찜찜한 일이 아니죠 ..
그래서검색을 해봤더니
osx 1.4 버전 부터 룰이 변경 되었습니다. 
cString --> UTF8String  변경 하여 사용 해야 합니다.
2011/06/08 19:27 2011/06/08 19:27
Posted
Filed under iphone

          +initialize 메소드는 클래스 메소드로서 클래스 객체를 초기화

          -init 메소드는 인스턴스 메소드로서 인스턴스 객체를 초기화

2011/06/07 22:12 2011/06/07 22:12