How to add a UIToolbar programmatically to an iOS app?

后端 未结 7 1101
太阳男子
太阳男子 2020-12-04 10:01

Can\'t seem to find a tutorial which does as the question title describes. I\'d like to understand just where the UIToolbar needs to be declared and how to get it onto my vi

7条回答
  •  爱一瞬间的悲伤
    2020-12-04 10:35

    Try this simple Method:

        UIToolbar *toolbar = [[UIToolbar alloc] init];
        toolbar.frame = CGRectMake(0, 0, 300, 44);
        UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"Send" style:UIBarButtonItemStyleDone target:self action:@selector(sendAction)];
    
        UIBarButtonItem *button2=[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleDone target:self action:@selector(cancelAction)];
    
        [toolbar setItems:[[NSArray alloc] initWithObjects:button1,button2, nil]];
        [self.view addSubview:toolbar];
    

提交回复
热议问题