2014-04-02 17 views
0

我的目標C相當新的,所以希望這一切有意義。我已經宣佈的UIView在.h文件中如何在IOS滑出式工具欄菜單添加按鈕編程

@property (strong, nonatomic) UIView *menuViewone; 

在.M文件我在viewDidLoad中

menuViewone =[[UIView alloc ]initWithFrame:CGRectMake(-400, 0, 200, 568) ]; 
[menuViewone setBackgroundColor:[UIColor whiteColor]]; 
[self.view addSubview:menuViewone]; 

宣佈的UIView,並設置按鈕的方法視圖框

- (IBAction)collectionmenutwo:(id)sender { 
    if (menuViewone.frame.origin.x >=0) { 
     [UIView animateKeyframesWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
      menuViewone.frame=CGRectMake(-400, 100, 300, 568); 
     } completion:^(BOOL finished) { 

     }]; 
    } 

    else 
    { 
     [UIView animateKeyframesWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
      menuViewone.frame=CGRectMake(200, 100, 300, 568); 
     } completion:^(BOOL finished) { 

     }]; 
    }} 

現在我想聲明在這個UIView中的按鈕...我怎麼可以做到這一點編程?

回答

1

只需將按鈕添加到您的菜單視圖的子視圖。

在聲明你的menuview之後,它看起來就像你的viewDidLoad。

UIButton *btn = [[UIButton] alloc] init]; 
btn.frame = CGRectMake(0,0,100,100); 
//set other button properties here. 
[menuViewone addSubview:btn]; 

對於更多的細節,你可以看看這個: How do I create a basic UIButton programmatically?

+0

按鈕沒有顯示在視圖 –

相關問題