简体   繁体   English

自定义可点击对象(按钮)IOS-目标C(Xcode5)

[英]Customized clickable object(button) IOS - Objective C (Xcode5)

I need to create a kind of clickable object, could be a button. 我需要创建一种可点击的对象,可以是一个按钮。 The graphic should be rectangle with text in the middle. 图形应为矩形,中间带有文本。 The rectangle should be clickable, like a button. 矩形应该像按钮一样可单击。 It should have four lables on the corners which should be able to hold integers. 它的拐角处应该有四个标签,它们应该能够容纳整数。 When clicking on those "labels", i need another action to be done, like again a button. 单击这些“标签”时,我需要执行另一项操作,例如再次单击按钮。

How on earth should i start with this? 我到底该如何开始呢?

Make a UIView subclass with five buttons (if they can be tapped, they should be buttons not labels) 用五个按钮制作一个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;

You will also need to connect an IBAction to tell when the buttons are tapped. 您还需要连接IBAction来告知何时点击按钮。

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

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

You can also create IBAction and hook the buttons up in the storyboard/xib 您也可以创建IBAction并将按钮挂在情节提要/ xib中

- (IBAction)middleButtonTapped
{

    //This method is called when the middle button is tapped
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM