gpt4 book ai didi

iOS : Radio Button Programatically Without using any Image

转载 作者:行者123 更新时间:2023-12-01 17:51:33 26 4
gpt4 key购买 nike

我一直致力于创建自定义 ui 控件,并想知道如何以编程方式将单选按钮添加到 UIView。

我只找到了一种解决方案,但它适用于 mac osx 应用程序控制。
所需结果的图像如下所示。
enter image description here

限制
不想使用图像。

谢谢。

最佳答案

单选按钮 - 如下设置角半径和板颜色。取三个按钮ViewController.h文件

@property(nonatomic,retain) IBOutlet UIButton *btn1;
@property(nonatomic,retain) IBOutlet UIButton *btn2;
@property(nonatomic,retain) IBOutlet UIButton *btn3;

- (IBAction)ClickBtn1:(id)sender;
- (IBAction)ClickBtn2:(id)sender;
- (IBAction)ClickBtn3:(id)sender;

ViewDidLoad方法。
- (void)viewDidLoad
{
[super viewDidLoad];

self.btn1.layer.cornerRadius = 10;
self.btn1.layer.borderColor = [[UIColor blackColor] CGColor];

self.btn2.layer.cornerRadius = 10;
self.btn2.layer.borderColor = [[UIColor blackColor] CGColor];

self.btn3.layer.cornerRadius = 10;
self.btn3.layer.borderColor = [[UIColor blackColor] CGColor];

// default

[self.btn1 setTitle:@"." forState:UIControlStateNormal];
[self.btn2 setTitle:@"" forState:UIControlStateNormal];
[self.btn3 setTitle:@"" forState:UIControlStateNormal];

}

按钮单击时的操作。
- (IBAction)ClickBtn1:(id)sender
{
[self.btn1 setTitle:@"." forState:UIControlStateNormal];
[self.btn2 setTitle:@"" forState:UIControlStateNormal];
[self.btn3 setTitle:@"" forState:UIControlStateNormal];
}
- (IBAction)ClickBtn2:(id)sender
{
[self.btn2 setTitle:@"." forState:UIControlStateNormal];
[self.btn1 setTitle:@"" forState:UIControlStateNormal];
[self.btn3 setTitle:@"" forState:UIControlStateNormal];
}
- (IBAction)ClickBtn3:(id)sender
{
[self.btn3 setTitle:@"." forState:UIControlStateNormal];
[self.btn1 setTitle:@"" forState:UIControlStateNormal];
[self.btn2 setTitle:@"" forState:UIControlStateNormal];
}

在您的 StoryBoard 按钮 View 中设置为以下高度和宽度 (20,20)的按钮。取标题名称点 (.) 及其字体大小 System 44.0并将边缘设置为下图。

enter image description here

您的单选按钮是:

enter image description here

关于iOS : Radio Button Programatically Without using any Image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29075438/

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