【问题标题】:Xcode UIView and subviewsXcode UIView 和子视图
【发布时间】:2014-05-07 09:17:07
【问题描述】:

首先,我是 xcode 和 Objective-c 编程的初学者。我用导航栏制作了我的应用程序,我有 UIView 和 Class1 类,我添加了新的子视图 Level1,但我不想添加新类。是否有任何解决方案如何从 ClassLesson1.m 向子视图 Level1 添加标签?

谢谢

【问题讨论】:

    标签: objective-c xcode uiview


    【解决方案1】:

    这样做很容易。让我们承认这是您的第 1 课视图代码。在 viewDidLoad 方法中你可以添加任何你想要的。

    - (void)viewDidLoad
    {
        UIView *level1 = [[UIView alloc] initWithFrame:CGRectMake(x,y,width,height)];
        [self.view addSubview:level1]
    
        UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(label_x,label_y,label_width,label_height)];
        label1.text = @"labeltext";
        [level1 addSubview:label1]
    }
    

    【讨论】:

      【解决方案2】:

      是的,你可以。

      以编程方式:

      // viewDidLoad method from Lesson1 class
      - (void)viewDidLoad
      {
          self.level1 = // Your UIView
      
          [self.view addSubview:self.level1]
          [self.level1 addSubview:yourLabel]
      }
      

      在第 1 课中使用 XIB 文件:

      将 UILabel 拖放到您的第 1 课中,并将 UILabel 与第 1 课上的 IBoutlet 链接。

      【讨论】:

      • 是的,我添加了新的 UIView(拖放),但我不知道在哪里可以命名它。对不起,我是新手。
      【解决方案3】:

      使用下面的链接。可能对你有帮助!! http://www.techotopia.com/index.php/An_iOS_7_Core_Data_Tutorial

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-21
        • 1970-01-01
        • 1970-01-01
        • 2019-03-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多