【问题标题】:How to access the properties of image declared in subclass of UIImageView in other controller class?如何访问其他控制器类中 UIImageView 子类中声明的图像属性?
【发布时间】:2016-07-21 04:03:47
【问题描述】:

我创建了一个类,它是 UIImageView 的子类。有像 imageFrame、centerPoint 和一个数组这样的属性。现在我必须初始化 UIImageView 的框架并在其他类中访问它,我该如何实现呢?

【问题讨论】:

    标签: ios objective-c uiimageview


    【解决方案1】:

    你可以只使用原生 UIImageView framecenter,因为你的类是 UIImageView 的子类,例如,yourUIImageViewSubclass.frame = CGRectMake(...

    如果你真的想使用你自己的属性,你可以在你的属性访问器中访问底层的原生属性,例如,

    - (CGRect)imageFrame
    {
       // other code go here
    
       return self.frame;
    }
    

    【讨论】:

      【解决方案2】:

      我不完全确定你在问什么,但是像这样初始化你的类的一个实例:

      SomeSubclass *foo = [[SomeSubclass alloc] initWithFrame:CGRectMake(20, 20, 20, 20)];
      

      添加到superView:

      [self.view addSubview:foo];
      

      访问公开的属性:

      foo.myArray ...
      foo.frame ...
      

      【讨论】:

      • 很高兴我能提供帮助,欢迎来到 Stack Overflow。不要忘记接受最佳答案为正确。快乐编码:)
      猜你喜欢
      • 2023-03-26
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多