UIToolbar에는 UIBarButtonItem이 추가될 수 있는데, 기본적으로 추가하게 되면 왼쪽부터 오른쪽까지 왼쪽으로 정렬되어 배치됩니다.
이러한 순서를 변경하여 왼쪽, 오른쪽 또는 가운데로 정렬할 수 있는데 이러한 효과를 주기 위해서는 다음과 같이 코드를 작성합니다.

UIBarButtonItem *flexibleSpaceLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *flexibleSpaceRight = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
// item은 가운데 정렬할 항목
[_toolbar setItems:[NSArray arrayWithObjects:flexibleSpaceLeft, item, flexibleSpaceRight, nil]];
[flexibleSpaceLeft release];
[flexibleSpaceRight release];


위의 코드와 같이 UIBarButtonSystemItemFlexibleSpace로 생성한 뒤 붙이게 되면 해당 부분은 가변 길이의 공백(?)이 됩니다.
위의 예에서는 가운데 정렬을 하였지만 왼쪽, 오른쪽 정렬을 하기 위해서는 UIBarButtonSystemItemFlexibleSpace로 된 객체를 하나만 만들고 가운데에 넣어주면 됩니다. 다음과 같이 말이죠.

[_toolbar setItems:[NSArray arrayWithObjects:itemLeft, flexibleSpaceCenter, itemRight, nil]];

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by 장현준

2009/06/16 13:14 2009/06/16 13:14
,
Response
No Trackback , a comment
RSS :
http://b4you.net/blog/rss/response/230


블로그 이미지

빗소리를 먹는 사람.

- 장현준

Notices

Archives

Authors

  1. 장현준

Recent Trackbacks

  1. 듀얼클러치의 생각 rsvin28's me2DAY 2009

Calendar

«   2012/02   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      

Site Stats

Total hits:
158014
Today:
84
Yesterday:
228