UIButton分组button

我正在尝试创build一个完全像这样的button:

替代文字

我将如何做到这一点? 有人可以告诉我的代码? 有没有办法像这样“分组”UIButtons?

你将要使用UITableViewController的部分设置为UITableViewStyleGrouped

每个组是一个部分,所以你会想要返回多less部分- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

对于每一节,你想指定有多less行- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

你需要用- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath来定制每个单元格- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath (顺便说一下,它告诉你在indexPathvariables中修改哪一部分的特定行) 。

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

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

希望这可以帮助!

这是一个具有两行(单元)的单组UITableView。 表格样式是UITableViewStyleGrouped。 我build议使用委托的–tableView:didSelectRowAtIndexPath:方法来响应单元格的select,而不是在单元格内使用UIButtons – 更好的视觉效果。

你不能这样分组uibuttons。 您可以通过几种方式实现这种外观,最优雅的是使用分组样式的uitableview。 但是,如果你只想让你的button看起来像这样,但不完全像这样,那么你也可以为你指定图像button。 丑陋的做法,但更简单…