简体   繁体   English

将UITableViewCell accessoryView与单元格底部对齐,而不是中间

[英]Align UITableViewCell accessoryView to bottom of cell instead of middle

In the native Mail app, the To: field has a ContactAdd UIButton on the right in the accessoryView position, but it is aligned to the bottom of the cell (which you can see as the cell grows in height). 在本机Mail应用程序中,To:字段在accessoryView位置的右侧有一个ContactAdd UIButton,但它与单元格的底部对齐(您可以看到单元格在高度上增长)。 Is it possible to mimic this using the accessoryView property? 是否可以使用accessoryView属性模仿这个? As far as I can tell, accessoryViews always align in the middle. 据我所知,accessoryViews总是在中间对齐。

我发现你可以继承UITableViewCell,覆盖layoutSubviews,并在该方法中,获取accessoryView并根据需要调整其框架。

In my app, I found a partly-working solution with the following code: 在我的应用程序中,我找到了一个部分工作的解决方案,其代码如下:

UIImage *accessoryImage = [UIImage imageNamed:@"accessory_disclosure_bottom.png"];
UIImageView *accImageView = [[UIImageView alloc] initWithImage:accessoryImage];
[accImageView setFrame:CGRectMake(0, 10, 14, 28)];
accImageView.backgroundColor = [UIColor greenColor];
accImageView.userInteractionEnabled = YES;
cell.accessoryView = accImageView;

I got the image from http://m.tech-recipes.com/rx/UITV_accessory_disclosure.png , cut away the bottom padding and made the background transparent in my graphics program. 我从http://m.tech-recipes.com/rx/UITV_accessory_disclosure.png获取了图像,剪掉了底部填充并使我的图形程序中的背景透明。 It has the full accessor functionality when selecting the row, however the image is not colored blue when selecting, which is really annoying (it seems to ignore the background transparency altogether). 它在选择行时具有完整的访问器功能,但选择时图像不是蓝色,这实在令人讨厌(它似乎完全忽略了背景透明度)。

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

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