ios - 以编程方式设置 RoundedRect 按钮

标签 ios objective-c ios7 uibutton

我尝试使用以下设置圆形按钮,但它从 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/

相关文章:

iphone - NSMutableArray 对象认为它是一个 NSArray :(

ios - 如何更改状态背景以不同于 iOS 7 上的导航栏?

ios - onShouldStartLoadWithRequest 在 iOS React Native 中自动调用 WebView 中加载任何 url,如何控制它?

ios - 如何在按下按钮时将值发送到 ViewController

ios - 在 UISearchDisplayController 中选择单元格后滚动到 UITableView 中选定的单元格?

ios - 尝试添加 UITapGestureRecognizer 但不工作

ios - id <SampleProtocolDelegate> 委托(delegate)与 id <SampleProtocolDelegate> _delegate

ios - UICollectionViewLayout:仅将 DecorationView 添加到特定单元格

ios - 如何在 ios 中设置用户对 FBLoginview 的读取权限?

php - 使用 Apple 登录 = invalid_client