iOS中的动态IBInspectable枚举

时间:2016-06-17 12:18:15

标签: ios objective-c user-interface ibinspectable

我用分段编写自定义控件(比如UISegmentControl) 我必须使用IBInspectable参数。

我有多个控件

@property IBInspectable int numberOfSegments;

在这里我如何绘制这些片段:

-(void) drawForAmountOfSegments {
    float segmentWidth = self.frame.size.width / numberOfSegments;
    float segmentHeight = self.frame.size.height;
    for (int i = 0; i < numberOfSegments; i++) {

       CGRect sgRect = CGRectMake(segmentWidth * i, 0, segmentWidth, segmentHeight);
       UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
       [button addTarget:self
                  action:@selector(segmentSelected:)
        forControlEvents:UIControlEventTouchUpInside];
       button.tag = i;
       button.frame = sgRect;
       button.backgroundColor = custom;
       [self addSubview: button];
    }
}

现在我想为这个按钮(片段)设置标题我想从IB中选择编辑控件,就像在segmentControl中一样。

enter image description here

据我所知,我需要一个包含所有段的数组,并选择其中一个来编辑其标题。 但我无法将NSArray设为IBInspectable 有什么建议如何解决这个问题?

*编辑*

例如,我需要从段的枚举中选择单段,并设置其参数。 选择第一段 - &gt;设置它的标题(我无法理解如何用IBInspectable实现它)

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以使用User Defined Runtime Attributes中的Identity Inspector。 所有可检查的属性实际上都在那里添加值。

相关问题