UIButton分组按钮

时间:2011-01-03 21:06:57

标签: ios iphone uibutton

我正在尝试创建一个如下所示的按钮:

alt text

我该怎么做?有人能告诉我代码吗?有没有办法像这样“组合”UIButtons?

3 个答案:

答案 0 :(得分:9)

您希望使用UITableViewController并将部分设置为UITableViewStyleGrouped

每个群组都是一个部分,因此您希望返回- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView所拥有的部分。

对于每个部分,您要指定- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section的行数。

您希望使用- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath自定义每个单元格(顺便提一下,它会告诉您在indexPath变量中要修改的哪个部分的特定行)。

最后,您将要使用XCode为您提供的模式处理- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath中的行单击:

[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];

希望这有帮助!

答案 1 :(得分:1)

这是一个包含两行(单元格)的单组UITableView。表格样式为UITableViewStyleGrouped。我建议使用委托的–tableView:didSelectRowAtIndexPath:方法响应单元格的选择,而不是在单元格中使用UIButtons - 更好的视觉效果。

答案 2 :(得分:0)

你不能把那样的uibutton分组。你可以通过几种方式实现这种外观,最优雅的是使用分组样式uitableview。 但是,如果您希望按钮看起来像这样,但不完全像这样,那么您也可以为按钮指定图像。 Uglier如何做到这一点,无论多么简单......