Views 5167 Votes 0 Comment 0
Atachment
Attachment '3'
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
구글에 비슷한 질문을 했더니 역시나 Stackoverflow에 누군가 같은 질문을 ㅋㅋ

Stackoverflow 질문 내용
Can I change horizontal position of UINavigationBar's title?
Like this image (MY ACCOUNT is the UINavigationBar title)
question.png



Stackoverflow 답변 내용
Change the position of the navigationbar title will be difficult.
In my experience, I could use either one of below two ways;

1. Set left button. When you set title and image both to UIButton, it will be exactly same look as like as you want. And set that button to the left button of navigationItem.

2. You can create new view which contains UILabel which have that position and set that view to navigationItem's titleView


위에서 설명한 내용을 작성한 코드

# 1번 내용 코드과 실행 내용
NSMutableArray *leftButtons = [[NSMutableArray alloc] init];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(2, 2, 40, 40)];
[button setBackgroundImage:[UIImage imageNamed:@"title_btn_back_w_nor"]
                  forState:UIControlStateNormal]; // SET the image name for your wishes
[button addTarget:self action:@selector(backButtonTapped)
 forControlEvents:UIControlEventTouchUpInside]; // you can ADD the action to the button as well like

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, 100, 44)];
[label setAttributedText:[[NSMutableAttributedString alloc]
                          initWithString:NSLocalizedString(@"My Closet", nil)
                          attributes:@{
                                       NSForegroundColorAttributeName:[UIColor whiteColor],
                                       NSFontAttributeName: [UIFont fontWithName:@"Futura-Medium" size:13]
                                       }]];

UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
[buttonView addSubview:button];
[buttonView addSubview:label];

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:buttonView];
[leftButtons addObject:backButton];
[self.navigationItem setLeftBarButtonItems:leftButtons animated:NO];

navi1.png


2번 내용 코드
NSMutableArray *leftButtons = [[NSMutableArray alloc] init];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
                               initWithImage:[UIImage imageNamed:@"title_btn_back_w_nor"]
                               style:UIBarButtonItemStylePlain
                               target:self
                               action:@selector(backButtonTapped)];
[leftButtons addObject:backButton];
[self.navigationItem setLeftBarButtonItems:leftButtons animated:NO];

UILabel* titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 44, 320, 44)];
titleLabel.textAlignment = NSTextAlignmentLeft;
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc]
                                             initWithString:NSLocalizedString(@"My Closet", nil)
                                             attributes:@{
                                                          NSForegroundColorAttributeName:[UIColor whiteColor],
                                                          NSFontAttributeName: [UIFont fontWithName:@"Futura-Medium" size:13]
                                                          }];
titleLabel.attributedText = attributedText;
self.navigationItem.titleView = titleLabel;

navi2.png


[참고] http://stackoverflow.com/questions/30007281/uinavigationbar-horizontal-position
?

List of Articles
No. Category Subject Author Date Views
249 Develop [ios] DatePicker iOS 6.x 이하 디자인. file hooni 2014.04.10 5113
248 Database [mysql] MySql 에서 정렬 후 그룹 하는 방법 hooni 2015.05.07 5098
247 System/OS [mac] 맥OSX에서 NTFS 쓰기 기능 활성화 hooni 2014.03.12 5075
246 Develop [c] Mac OS 에 gmp(gmp.h) 라이브러리 설치 hooni 2016.10.03 5055
245 Develop [ios] Xcode를 사용해서 Static Library 만들기 (시뮬레이터 + 디바이스) file hooni 2015.01.03 5049
244 Develop [ios] 아이폰 GPS 사용하기 hooni 2014.05.24 5026
243 Develop [android] 코드에서 문자열로 Resource 가져오기 hooni 2015.07.09 5001
242 Develop [ios] 애플 앱스토어 IDFA 리뷰 정책 변경 안내 file hooni 2014.05.07 4997
241 Develop [ios] How to set up clang formatter hooni 2015.09.17 4981
240 Develop [ios] UDID 사용 제한에 따른 대안들 hooni 2014.03.13 4971
239 System/OS 서버 확장을 위한 두 가지 방법 file hooni 2018.08.29 4956
238 Etc 원어민이 매일 쓰는 일상표현 150개 file hooni 2023.09.17 4872
237 Etc How to completely Uninstall Coda hooni 2017.10.24 4866
236 Develop [ios] 앱 딜리게이트 얻어오기. (AppDelegate) hooni 2014.05.10 4765
235 Develop [matlab] ZigZag-Scanning (2-D Array) file hooni 2016.10.15 4760
234 Develop [ios] NSString URL Encode/Decode (인코딩/디코딩) hooni 2014.05.02 4749
Board Pagination Prev 1 ... 57 58 59 60 61 ... 74 Next
/ 74