Ios 以编程方式设置RoundedRect按钮

Ios 以编程方式设置RoundedRect按钮,ios,objective-c,ios7,uibutton,Ios,Objective C,Ios7,Uibutton,我试着用下面的按钮设置圆形按钮,但它从视图中消失了。如果我删除了 takebtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 然后显示矩形按钮。帮我拿一下圆形的选择按钮 takebtn = [[UIButton alloc]initWithFrame:CGRectMake(30, 325, 250, 40)]; takebtn = [UIButton buttonWithType:UIButtonTypeRoundedRe

我试着用下面的按钮设置圆形按钮,但它从视图中消失了。如果我删除了

takebtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
然后显示矩形按钮。帮我拿一下圆形的选择按钮

 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框架

UIButton* takebtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[takebtn setFrame:CGRectMake(30, 325, 250, 40)];
[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];

+1考虑到给出的代码,这是一个更好的答案,因为OP代码清楚地表明第1行和第2行存在泄漏。