gpt4 book ai didi

iphone - 栏按钮项目以编程方式添加工具栏

转载 作者:行者123 更新时间:2023-12-03 20:25:17 24 4
gpt4 key购买 nike

我想以编程方式将按钮而不是栏按钮项目添加到工具栏中。我选择它是因为按钮默认图像信息为暗。

那么这是如何以编程方式完成的呢?

最佳答案

UIImage* image = [UIImage imageNamed:defaultImage];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
UIButton* button = [[UIButton alloc] initWithFrame:frame];
[button setTitle:@"Display" forState:UIControlStateNormal & UIControlStateHighlighted];
[button setImage:image forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:selectedImage] forState:UIControlStateSelected];
[button addTarget:self action:@selector(button_Clicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];

关于iphone - 栏按钮项目以编程方式添加工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10444104/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com