- Posted
- Filed under 01010101
Categories 는 이미 존재하는 클래스에 새로운 메소드를 추가할 수 있는 기능입니다.
1. 아이폰 네비게이션바 배경이미지 사용하기
[code]//
// UINavigationBar.h
//
// Created by Cho, Young-Un on 11. 3. 30..
// Copyright 2011 cultstory.com. All rights reserved.
//
@interface UINavigationBar (UINavigationBarCategory)
@end[/code]
[code]//
// UINavigationBar.m
//
// Created by Cho, Young-Un on 11. 3. 30..
// Copyright 2011 cultstory.com. All rights reserved.
//
#import "UINavigationBar.h"
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"NavigationBarBg.png"];
[image drawInRect:rect];
}
@end[/code]
2. 아이폰 네비게이션바 제목 가운데 정렬하기
[code]//
// UINavigationItem.h
//
// Created by Cho, Young-Un on 11. 3. 30..
// Copyright 2011 cultstory.com. All rights reserved.
//
@interface UINavigationItem (UINavigationItemCategory)
@end[/code]
[code]//
// UINavigationItem.m
//
// Created by Cho, Young-Un on 11. 3. 30..
// Copyright 2011 cultstory.com. All rights reserved.
//
#import "UINavigationItem.h"
@implementation UINavigationItem (UINavigationItemCategory)
- (void)setTitle:(NSString *)title {
UIFont *font = [UIFont fontWithName:@"NanumGothicExtraBold" size:20.0f];
CGSize size = [title sizeWithFont:font];
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(320 - size.width / 2, 0, size.width, 44)] autorelease];
label.backgroundColor = [UIColor clearColor];
label.textColor = RGB(89, 78, 56);
label.font = font;
label.text = title;
self.titleView = label;
}
@end[/code]