0

我需要创建一种可点击的对象,可以是一个按钮。图形应该是矩形,中间有文字。矩形应该是可点击的,就像一个按钮。它的角落应该有四个标签,应该能够容纳整数。当点击那些“标签”时,我需要做另一个动作,就像一个按钮。

我到底应该如何开始呢?

4

1 回答 1

1

用五个按钮创建一个 UIView 子类(如果可以点击它们,它们应该是按钮而不是标签)

@property (nonatomic, weak) IBOutlet UIButton *middleButton;
@property (nonatomic, weak) IBOutlet UIButton *topLeftButton;
@property (nonatomic, weak) IBOutlet UIButton *topRightButton;
@property (nonatomic, weak) IBOutlet UIButton *bottomLeftButton;
@property (nonatomic, weak) IBOutlet UIButton *bottomRightButton;

您还需要连接一个 IBAction 来判断按钮何时被点击。

[self.middleButton addTarget:self action:@selector(middleButtonTapped) forControlEvents:UIControlEventTouchUpInside];

- (void)middleButtonTapped
{
    //This method is called when the middle button is tapped
}

您还可以创建 IBAction 并将按钮连接到故事板/xib

- (IBAction)middleButtonTapped
{

    //This method is called when the middle button is tapped
}
于 2013-10-19T21:25:45.767 回答