如何使用MonoTouch在iPhone上添加RadioButton和CheckBox?

时间:2011-04-12 12:46:13

标签: iphone interface-builder xamarin.ios

我查看了Interface Builder和UI组件。但是没有RadioButton和CheckBox。是否有其他方法来添加这些组件?我使用MonoTouch开发iPhone应用程序。

2 个答案:

答案 0 :(得分:1)

是的朋友,你必须添加一个图像 在.h文件中

int editCount;  
int check;

in viewdidload{

editCount = 0;
    check = 0;
}

if( check == 0 )
    {       
        UIButton *selectedButton = (UIButton *)sender;

        if (editCount%2 == 0) {
            [(UIButton *)[self.view viewWithTag:160] setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"TICKIMAGE",[selectedButton tag]] ofType:@"png"]] forState:UIControlStateNormal];

}
else {

            [(UIButton *)[self.view viewWithTag:160] setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"PLAINBUTTON",[selectedButton tag]] ofType:@"png"]] forState:UIControlStateNormal];       

}

editcount++;
}

这项工作类似于单选按钮你必须使用tickimage和plainbutton图像那里..好友

答案 1 :(得分:1)

您可以使用以下方法之一代替单选按钮:

  • UISegmentedControl
  • UITableView控制器中用于选项的专用行
  • 自己动手

对于快速内联的东西,使用UISegmentedControl,当这是一个新的上下文或有太多选项时,使用从UINavigationController推送的嵌套UITableView控件,如果只有少数几个选项,您可以将UITableView中的几行专用于无线电选项并自行运行。

MonoTouch.Dialog(我自己的外部库)提供了一种创建UITableView控制器的简便方法,特别是像您使用UITableView解决方案创建的那样的单选按钮功能。

对于复选框,您可以在UITableView单元格上使用装饰,也可以使用滑块控件进行“开/关”设置。

同样,如果您使用UItableView方法,MonoTouch.Dialog会为您完成大部分工作。

从以下网址下载代码和示例:

http://github.com/migueldeicaza/MonoTouch.Dialog