Develop
2013.04.23 18:06

[ios] 자주 쓰는 패턴과 API

조회 수 17734 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
//background 배경이미지 넣기 
self.view.backgroundColor =
    [UIColor colorWithPatternImage:
        [UIImage imageWithContentsOfFile:
            [[[NSBundle mainBundle] resourcePath]
                stringByAppendingPathComponent:@"intro_bg_01.png"]]]; 


//UIImage UIimageView 이미지 붙이기 
UIImage *img = [UIImage imageNamed:@"notice_bg.png"];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
[imgView setFrame:CGRectMake(0, 0, img.size.width, img.size.height)];
[self.view addSubview:imgView];
[img release];
[imgView release];


//UIImage UIButton 
UIImage *img = [UIImage imageNamed:@"res_btn_01.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

button.frame =
    CGRectMake(230, 100/2 -img.size.height/2,
        img.size.width, img.size.height);

[button addTarget:self
    action:@selector(infoAction)
    forControlEvents:UIControlEventTouchUpInside];
    
[button setImage:img forState:UIControlStateNormal];
[button setImage:img forState:UIControlStateHighlighted];
[cell addSubview:button];


//UILabel 
int x=0;
int y=0;
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(x, y, 100, 100)];

// label.textColor =
// [UIColor colorWithRed:136/255.0 green:112/255.0 blue:79/255.0 alpha:1];

label.text = [[dataArray objectAtIndex:indexPath.row] objectForKey:@"time"];

// label.font = [UIFont systemFontOfSize:13.0f];

[label setNumberOfLines:0];

//길면 줄 바꿈됨
[label setLineBreakMode:UILineBreakModeWordWrap];

[self.view addSubview:label];
label.backgroundColor = [UIColor clearColor];


//event 
- (void) buttonAction:(id)sender { 
    NSLog(@"click");

    UIButton *button = (UIButton*)sender;

    switch (button.tag) { 
        //대기중 
        case 0:
            [self setWaitingData];
            break;

        //완료된 면접
        case 1:
            [self setDoneData];
            break;

        default:
            break;
    }
}

- (void) toggleMenuAction {
    toggleView = !toggleView;
    
    for (UIButton *button in self.view.subviews) { 
        if(button!=nil && [button isKindOfClass:[UIButton class]]
            && (button.tag==0 || button.tag==1 || button.tag==2 )) {
            button.hidden = toggleView;
        }
    }

    // [closeButton removeFromSuperview];
    menuButton.selected = toggleView;
} 


//UIScrollView는 self.view에 붙여야 한다.
UIView를 상속붙은 콤포넌트들(UIImageView 등등) 에 붙이면안그럼 스크롤 안붙는다.
UIScrollView *scView =
    [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 480, 320)];
[scView setScrollEnabled:YES];
[scView setContentSize:CGSizeMake(2000, 500)];
[self.view addSubview:scView];


//네비게이션 색상 바꾸기 (하나의 클래스 안에 선언하면 모든 클래스에 적용된다) 
[출처] http://www.developers-life.com/custom-uinavigationbar-with-image-and-back-button.html
@implementation UINavigationBar (CustomImage) 
- (void)drawRect:(CGRect)rect { 
    //이미지 
    // UIImage *image = [UIImage imageNamed: @"menu_big_bg_01_r.png"]; 
    // [image drawInRect:
    // CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 

    //배경 색깔 (베니 바탕만 바뀐다) 
    // UIColor *color = [UIColor blackColor]; 
    // CGContextRef context = UIGraphicsGetCurrentContext(); 
    // CGContextSetFillColor(context,
    //     CGColorGetComponents( [color CGColor])); 
    // CGContextFillRect(context, rect); 


    //버튼과 네비 배경까지 검은색으로 다 바뀐다 
    [self setTintColor:[UIColor colorWithRed:0.0f 
        green: 0.0f 
        blue:0.0f 
        alpha:1]]; 
} 


//네비게이션 바 뒤로 가기 
[self.navigationController popToRootViewControllerAnimated:YES];


//네비게이션 바 이름 
// self.title = @"대입정보";
self.navigationItem.title = @"대입정보";

self.title = @"대입정보";
// 으로 하면 tabbar에도 이름이 들어간다.
// 만약 커스텀 탭바에서 이것 쓰면 낭패~


//네비게이션바 숨기기
- (void) viewWillAppear:(BOOL)animated {
    [[self navigationController] setNavigationBarHidden:YES animated:NO];
}



//네비게이션바 보이기
- (void) viewWillAppear:(BOOL)animated { 
    [[self navigationController] setNavigationBarHidden:NO animated:YES]; 
} 


//네비게이션바 이름
self.navigationItem.title = @"대입정보";


//네비게이션바 푸쉬
[self.navigationController pushViewController:listViewController animated:YES];


//alert
UIAlertView* alert = [[UIAlertView alloc]
    initWithTitle:@"수강신청 완료"
    message:@"수강신청이 완료 되었습니다."
    delegate:self cancelButtonTitle:@"확인" otherButtonTitles:nil, nil];

[alert show];
[alert release];


//UITalbeView
#import <UIKit/UIKit.h>

@interface PortfolioChangeViewController : UIViewController
<UITableViewDelegate, UITableViewDataSource>
{
    UITableView *listTableView; 
    NSMutableArray *tableDataArray;//뿌려줄데이타들(검색결과 && 원본 깊은복사본)
    int cellCount;
    int more;
    int heightCell;
}
- (void) setData:(int)num;
@end 


#import "PortfolioChangeViewController.h"

@implementation PortfolioChangeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil
    bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    
    if (self) {
        // Custom initialization 
    }
    return self;
}

- (void)dealloc 
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning 
{
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use. 
}

#pragma mark - View lifecycle 

/* 
// Implement loadView to create a view hierarchy programmatically,
// without using a nib. 
- (void)loadView 
{
}
*/

// Implement viewDidLoad to do additional setup after loading the view,
// typically from a nib. 
- (void)viewDidLoad 
{
    [super viewDidLoad];
    
    self.navigationItem.title = @"포트폴리오 변경";
    heightCell = 3+3+43;

    //table 
    listTableView =
        [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 377)];
        
    [listTableView setDelegate:self];
    [listTableView setDataSource:self];
    [listTableView setScrollEnabled:YES];
    [listTableView setAutoresizesSubviews:YES];
    listTableView.backgroundColor = [UIColor clearColor];
    listTableView.separatorStyle = YES;
    [self.view addSubview:listTableView];
}

- (void)viewDidUnload 
{
    [super viewDidUnload];
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation 
{
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void) setData:(int)num
{
    //데이타
    tableDataArray = [[NSMutableArray alloc]init];
    [tableDataArray addObject:[NSDictionary
        dictionaryWithObjectsAndKeys:
            @"미래를 꿈꾸는 기획자", @"subject", @"1", @"num", nil]];
            
    [tableDataArray addObject:
        [NSDictionary dictionaryWithObjectsAndKeys:
            @"꿈꾸는 아이폰 개발자", @"subject", @"2", @"num", nil]];
        
    [tableDataArray addObject:
        [NSDictionary dictionaryWithObjectsAndKeys:
            @"재미있는 디자이너의 꿈", @"subject", @"3", @"num", nil]];

    more = 0;
    if([tableDataArray count]>10){
        cellCount = 10+1;
        more = 1;//더보기 있을때 
    }else{
        more = 0;//더보기 없을때 
        cellCount = [tableDataArray count];
    }
}

#pragma tableView 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections. 
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView
    numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section. 
    // return [tableDataArray count];
    return cellCount;
}

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView
    cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    // UITableViewCell *cell =
        [[[UITableViewCell alloc]
            initWithStyle:UITableViewCellStyleSubtitle
            reuseIdentifier:CellIdentifier] autorelease];

    UITableViewCell *cell =
        [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell =
            [[[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleSubtitle
                reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell... 
    NSDictionary *dic = [tableDataArray objectAtIndex:indexPath.row];

    CGRect frame = cell.textLabel.frame;
    frame.size.width = 320;
    cell.textLabel.frame = frame;

    //더 보기 그리기 
    if (more==1 && indexPath.row+1 == cellCount) {
        cell.textLabel.text = @"더 보기";
    }
    //내용 그리기 
    else 
    {
        //텍스트 
        cell.textLabel.text =
            [NSString stringWithFormat:@"%@",
                [dic objectForKey:@"subject"]];
        // [cell.textLabel setFont:[UIFont systemFontOfSize:14]];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //더보기 버튼 눌렀을때 
    if(more == 1 && indexPath.row+1 == cellCount){
        NSLog(@"더보기 클릭");

        //마지막 페이지 인지 확인 
        if (cellCount-1 < [tableDataArray count]) {
            if (([tableDataArray count] - cellCount) >= 10 ) {
                cellCount += 10;
            }else{
                cellCount += ([tableDataArray count] - cellCount);
                // cellCount --;
                more = 0;
            }
        }
        
        [listTableView reloadData];
    }
    //다음화면 넘기기 
    //상세화면 들어가기 
    else 
    {
    }

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

// cell height 
-(CGFloat) tableView:(UITableView *)tableView
    heightForRowAtIndexPath:(NSIndexPath *) indexPath
{
    return heightCell;
}


//동기식 (팜즈싱크에서 동기로 했을때)
NSString *urlString =
    NSString stringWithFormat:
        @"http://59.10.50.79:8080/sync/delete.jsp?ID=%@&AppName=%@&data=%@",
        encodedUrl2, encodedUrl37, encodedUrl11];

NSURL *nsurl =[NSURL URLWithString:urlString];
NSMutableURLRequest *request0 =
    [NSMutableURLRequest requestWithURL:nsurl
        cachePolicy:NSURLRequestUseProtocolCachePolicy
        timeoutInterval:60.0];

NSHTTPURLResponse *response;
NSError *error;
NSData *recive =
    [NSURLConnection
        sendSynchronousRequest:request0
        returningResponse:&response error:&error ];


//동기식 (간단한 다른 방법)
[NSString stringWithContentsOfURL:
    [NSURL URLWithString: stringEntryURL]
    encoding: 0x80000003 error: &error];
    
[NSString stringWithContentsOfURL:
    [NSURL URLWithString: stringEntryURL]
    encoding: CFStringConvertEncodingToNSStringEncoding(0x00000422)
    error: &error];
    
[NSString stringWithContentsOfURL:
    [NSURL URLWithString: stringEntryURL]
    encoding: 0x80000940
    error: &error];

[NSString stringWithContentsOfURL:
    [NSURL URLWithString: stringEntryURL]
    encoding: NSUTF8StringEncoding
    error: &error];

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
729 Develop [ios] Swift 4 String, Date, DateFormatter 예제 hooni 2018.10.18 1520
728 Develop What is difference between Get, Post, Put and Delete? hooni 2018.02.28 1577
727 Develop How to Test SMTP AUTH using Telnet hooni 2018.04.05 1596
726 Develop [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 file hooni 2021.01.29 1608
725 Develop [android] 레이아웃 사이즈 변경 (동적; programmatically) hooni 2016.11.07 1625
724 Develop [ios] binary를 C코드로 변환 file hooni 2015.01.03 1653
723 Develop [ios] 스크린 캡쳐 (전원버튼 + 홈버튼) 호출 알아내기 hooni 2014.11.19 1660
722 Develop [ios] Swift 4 Singleton inheritance hooni 2018.10.31 1695
721 Develop [js] 모바일 스크롤 방지(해제) hooni 2015.04.14 1701
720 Develop [python] 파라미터 앞에 *, ** 의 의미? (*args, **kwargs) hooni 2019.11.22 1708
719 Develop ZBar 라이브러리를 이용한 바코드 스캔 앱 개발하기 file hooni 2015.01.01 1736
718 Develop [ios] Requesting Location Permissions in iOS file hooni 2018.08.18 1746
717 Develop [ios] Locale Identifiers file hooni 2018.11.29 1748
716 Develop [web] 더 빠른 웹을 위한 프로토콜, 'HTTP/2' file hooni 2014.10.20 1770
715 Develop [ios] 동영상 플레이어 샘플 (for Remote Url) file hooni 2017.02.07 1771
714 Develop [ios] How To Use UIScrollView to Scroll and Zoom Content (Using Objective-C) file hooni 2016.03.23 1772
Board Pagination Prev 1 ... 6 7 8 9 10 ... 53 Next
/ 53