简体   繁体   English

如何在InAppSettingsKit设置视图(iPhone / iPad)中添加按钮?

[英]How do I add a button to the InAppSettingsKit setting view (iPhone/iPad)?

I have been looking at the sample app provided by InAppSettingsKit and I noticed the use of a couple of buttons: 我一直在看InAppSettingsKit提供的示例应用程序,我注意到使用了几个按钮:

在此输入图像描述

I would like to integrate a single red button in my app called reset, however I'm not sure how to do it. 我想在我的应用程序中集成一个名为reset的红色按钮,但是我不知道该怎么做。 I've had a look at the code in the sample app and I'm a bit lost with it all. 我已经看过示例应用程序中的代码了,我有点迷失了。 Please could someone help me out? 请有人帮帮我吗?

After spending a while searching through all the code and plists I managed to find the answer to my question. 花了一段时间搜索所有代码和plists后,我设法找到了我的问题的答案。 For those who are interested what you need to do is the following: 对于那些感兴趣的人,您需要做的是以下内容:

  1. Add a row to your Root.plist file with the Type set to IASKButtonSpecifier . IASKButtonSpecifier文件中添加一行,并将Type设置为IASKButtonSpecifier
  2. Set the Identifier on this row as something useful eg 'myButton1'. 将此行上的标识符设置为有用的内容,例如“myButton1”。
  3. Add the following delegate method to the viewController you loaded the InAppSettingsKit from: 将以下委托方法添加到您从以下位置加载InAppSettingsKit的viewController:

     - (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForKey:(NSString*)key { if ([key isEqualToString:@"myButton1"]) { // Do some actions... } } 

It's worth noting that the key is equal to the identifier you set in the Root.plist. 值得注意的是,密钥等于您在Root.plist中设置的标识符。

The only thing I haven't worked out yet is how to change the colour of the button; 我还没有解决的唯一问题是如何改变按钮的颜色; however I suspect this may be possible by overriding a method. 但我怀疑这可能是通过覆盖方法来实现的。

Great that you already found part of the solution. 很高兴你已经找到了解决方案的一部分。 To customize the look, you should create a custom view using the IASKCustomViewSpecifier documented on http://www.inappsettingskit.com/ . 要自定义外观,您应该使用http://www.inappsettingskit.com/上记录的IASKCustomViewSpecifier创建自定义视图。 The yellow icon for instance is making use of this. 例如,黄色图标正在利用它。 In your case, you could return an instance of UIButton with a red background color (or a custom background image). 在您的情况下,您可以返回具有红色背景颜色(或自定义背景图像)的UIButton实例。

In this case, you don't need the buttonTappedForKey method to get the tap event but configure the target/action of your button as usual. 在这种情况下,您不需要使用buttonTappedForKey方法来获取tap事件,而是像往常一样配置按钮的目标/操作。

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

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