답변

0

나는 비슷한 것을했습니다. 두 개의 UIButton을 탐색 항목/막대에 추가했습니다. 두 개의 UIButton이있는 UIView 하위 클래스를 만듭니다. 그런 다음 같은 것을 할 수 있습니다

MyUIViewSubclass *tempview = [[[MyUIViewSubclass alloc] initWithFrame:CGRectMake(234,4,84,30)] autorelease]; 
UIBarButtonItem newButton = [[[UIBarButtonItem alloc] initWithCustomView:tempview] autorelease]; 
[self.navigationItem setRightBarButtonItem:newButton animated:NO]; 

당신이해야 할 모든 레이아웃 MyUIViewSubclass의 버튼이며, 당신은 좋은거야.

또한 대상의 ID를 사용자 정의 된 init 명령에 전달하여보기에서 단추를보다 쉽게 ​​대상으로 지정합니다.

- (id)initWithFrame:(CGRect)aRect andTarget:(id)newTarget { 
    if (self = [super initWithFrame:aRect]) { 



     UIButton *editbtn = [[[UIButton alloc] initWithFrame:fframe] autorelease]; 
     [editbtn addTarget:newTarget action:@selector(MBEdit) forControlEvents:UIControlEventTouchUpInside]; 

     [self addSubview:editbtn]; 
     [self setFirstbutton:editbtn]; 
     [editbtn release]; 



     UIButton *newbtn = [[[UIButton alloc] initWithFrame:fframe] autorelease]; 
     [newbtn addTarget:newTarget action:@selector(MBNew) forControlEvents:UIControlEventTouchUpInside]; 

     [self addSubview:newbtn]; 
     [self setSecondbutton:newbtn]; 
     [newbtn release]; 

    } 

    return self; 

} 
+0

하지만 UICutton을 내비게이션 막대 단추처럼 보이게하려면 직접 페인트해야합니다. 나에게 UISegmentedControl을 사용하면 매우 행복 할 것입니다. (이것은 그림의 번거 로움을 덜어줍니다.)하지만 실제로 필요한 것은 +와 원래의 iPhone 휴지통 아이콘입니다. 그래도 더 우아한 솔루션 (굵은 글씨와 쓰레기통을위한 유니 코드 문자 코드가있는 것)을 선호합니다. – MrMage

+0

저는 실제로 스크린 샷을 찍었고 버튼에 이미지를 사용했습니다. 거의 두 가지 버튼 대신 뷰에 분할 된 컨트롤을 추가 할 수도 있습니다. 그것도 잘 작동합니다. – mjdth

1

당신은 sample code하는 UIToolbar에 그들을 배치하여 탐색 항목에 여러 개의 버튼을 추가 할 수 있습니다 MyUIViewSubclass 대신 initWithFrame에 대한 그래서, 나는 이런 식으로 뭔가가있다.

관련 문제