我尝试使用以下设置圆形按钮,但它从 View 中消失了。如果我删除了
takebtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
然后显示矩形按钮。帮助我获取 RoundedRect 按钮。
takebtn = [[UIButton alloc]initWithFrame:CGRectMake(30, 325, 250, 40)];
takebtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[takebtn setTitle:@"Take Photo" forState:UIControlStateNormal];
takebtn.backgroundColor=[UIColor colorWithRed:50.0/255.0 green:205.0/255.0 blue:50.0/255.0 alpha:1.0];
[takebtn addTarget:self
action:@selector(takePhoto:)
forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[nextview addSubview:takebtn];
最佳答案
您需要像下面这样修改您的代码:-
takeBtn.layer.cornerRadius = 10; //value can be change accordingly.
takeBtn.clipsToBounds = YES;
注意:- ios7 中无需导入 Quartz 框架
关于ios - 以编程方式设置 RoundedRect 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24721475/