UITableView样式分组中的自定义selectedBackgroundView出站 [英] custom selectedBackgroundView outbound in UITableView Style Grouped

查看:126
本文介绍了UITableView样式分组中的自定义selectedBackgroundView出站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


使用UITableView Style Grouped后,使用selectedBackgroundView时出现问题自定义颜色。

After use UITableView Style Grouped, it have a problem when use selectedBackgroundView with custom color.

它在那里画UITableViewCell。
是否有可能将它们限制在绑定范围内?

it draw outside of there UITableViewCell. Is it possible to clip them in bound ?

推荐答案

我遇到了类似的问题,但没有找到任何简单的简单的方法来解决。我为UIImage制作了类别并使用了几张图片来捕捉所有情况。

I had similar problems and didn't find any simple and easy method to solve. I maked category for UIImage and used several images for catch all cases.


  • single_cell_bg.png - 带有圆角的图像

  • top_cell_bg - 带圆角的图像

  • .....

不那么优雅但工作

@interface UIImage (CellBacground)
- (UIImage *)backgroundCellViewforRow:(NSInteger)row totalRow:(NSInteger)total;
@end



#import "UIImage+CellBacground.h"

@implementation UIImage (CellBacground)

- (UIImage *)backgroundCellViewforRow:(NSInteger)row totalRow:(NSInteger)total {
    NSString *path = NULL;
    if (row == 0) {
        if(total == 1) {
            path = [[NSBundle mainBundle] pathForResource:@"single_cell_bg" ofType:@"png"];
        } else {
            path = [[NSBundle mainBundle] pathForResource:@"top_cell_bg" ofType:@"png"];
        }
    } else {
        if ((total - row) == 1) {
            path = [[NSBundle mainBundle] pathForResource:@"bottom_cell_bg" ofType:@"png"];
        } else {
            path = [[NSBundle mainBundle] pathForResource:@"middle_cell_bg" ofType:@"png"];
        }
    }
    UIImage *theImage = [[UIImage alloc] initWithContentsOfFile:path];
    UIEdgeInsets imInset = UIEdgeInsetsMake(10, 10, 10, 10);
    UIImage *strImage = [theImage resizableImageWithCapInsets:imInset];
    return strImage;
}
@end

在tableView中调用:cellForRowAtIndexPath:

Call in tableView:cellForRowAtIndexPath:

UIImage *backImage = [[UIImage alloc] init];
[backImage backgroundCellViewforRow:indexPath.row totalRow:[tableView numberOfRowsInSection:indexPath.section]];
UIImageView *backview = [[UIImageView alloc] initWithImage:backImage];
cell.selectedBackgroundView = backview;

这篇关于UITableView样式分组中的自定义selectedBackgroundView出站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆