开发者

How to add a textField to a toolbar

I have a toolbar where I want to post a textField. I'm trying with the following code but it doesn't work:

 UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"Item" style开发者_StackOverflow社区:UIBarButtonItemStyleBordered target:self action:@selector(action:)];

 UITextField *customItem1 = [[UITextField alloc] init];

     NSArray *items = [NSArray arrayWithObjects: customItem, customItem1, nil]; 
[self setToolbarItems:items animated:YES];


The toolbar items must all be UIBarButtonItems. In order to display something else, you embed a view into the item:

UIBarButtonItem *customItem1 = [[UIBarButtonItem alloc] initWithCustomView:view];
//view is the embedded view, in your case a UITextField
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜