【问题标题】:How To Add button in a Slide-out Sidebar Menu in ios programmatically如何以编程方式在 ios 的滑出式侧边栏菜单中添加按钮
【发布时间】:2014-04-02 07:20:45
【问题描述】:

我是 Objective c 的新手,所以希望这一切都有意义.. 我在 .h 文件中声明了 UIView

@property (strong, nonatomic) UIView *menuViewone; 

在 .m 文件中,我在 viewdidload 中声明了 UIView

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

并在Button方法中设置视图框架

 - (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 中声明按钮......我如何以编程方式做到这一点?

【问题讨论】:

    标签: ios iphone objective-c 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?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多