2014-07-13 110 views
0

我嘗試使用以下設置Rounded按鈕,但它從視圖中消失。如果我刪除了以編程方式設置RoundedRect按鈕

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

回答

1

需要修改類似下面的代碼: -

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

注: - 無需導入Quartz框架在ios7

1

試試這個

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

+1考慮到給出的代碼,這是更好的答案,因爲OP代碼清楚地表明第1和第2行泄漏。 –