【问题标题】:Set RoundedRect Button Programmatically以编程方式设置 RoundedRect 按钮
【发布时间】:2014-09-03 11:32:10
【问题描述】:

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

takebtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

然后它显示矩形按钮。帮我拿到 RoundedRect Button。

 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];

【问题讨论】:

    标签: ios objective-c ios7 uibutton


    【解决方案1】:

    你需要像下面这样修改你的代码:-

    takeBtn.layer.cornerRadius = 10; //value can be change accordingly.
    takeBtn.clipsToBounds = YES;
    

    注意:- ios7 无需导入 Quartz 框架

    【讨论】:

      【解决方案2】:

      试试这个

      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 行有泄漏。
      猜你喜欢
      • 2014-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-09
      相关资源
      最近更新 更多