How to programmatically replace UIToolBar items built in IB

后端 未结 8 885
我在风中等你
我在风中等你 2020-12-13 21:35

I have a toolbar with various image buttons, created in Interface Builder.

I\'d like to be able to programmatically replace one of the buttons with an activity indic

8条回答
  •  萌比男神i
    2020-12-13 22:35

    Try:

    - (void)setTitle:(NSString *)title forItem:(int)item ofToolbar:(UIToolbar *)tb {
        NSMutableArray *newItems = [tb.items mutableCopy];
        UIBarButtonItem *old = [newItems objectAtIndex:1],
        *titled = [[UIBarButtonItem alloc] initWithTitle:title style:old.style target:old.target action:old.action];
    
        [newItems  replaceObjectAtIndex:1 withObject:titled];
        tb.items = newItems;
    
        [titled release];
    }
    

提交回复
热议问题