目标c中带有三个按钮(带图标)的自定义单元格

时间:2017-03-11 02:47:27

标签: ios objective-c uibutton uikit

我正在使用PSButtonCell进行链接,但是三个单独的链接占用了太多空间,因此我尝试创建一个带有三个按钮的自定义单元格;基本上就像3个浮动图标。

我已经获得了一些用图标创建tableview的代码,但目前我不知道如何正确分隔它们(所有图标当前重叠),我不知道应该如何添加tap tapners对观点。这看起来像我可以修改做我想要的东西吗?如果没有,他们可以为我提供更好的解决方案吗?非常感谢我的图标代码

- (id)tableView:(id)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 1) {
        UIView *headerView = [[UIView alloc] initWithFrame:(CGRect){{0, 0}, {320, kHeaderHeight}}];
        headerView.backgroundColor = UIColor.clearColor;
        headerView.clipsToBounds = YES;

        // icon
        UIImage *bugicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/Bug.png", kSelfBundlePath]];
        UIImageView *bugiconView = [[UIImageView alloc] initWithImage:bugicon];
        bugiconView.frame = (CGRect){{0, 21}, bugiconView.frame.size};
    //  bugiconView.center = (CGPoint){headerView.center.x, bugiconView.center.y};
        bugiconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
        [headerView addSubview:bugiconView];

        UIImage *payicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/Paypal.png", kSelfBundlePath]];
        UIImageView *payiconView = [[UIImageView alloc] initWithImage:payicon];
        payiconView.frame = (CGRect){{0, 21}, payiconView.frame.size};
    //  payiconView.center = (CGPoint){headerView.center.x, payiconView.center.y};
        payiconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
        [headerView addSubview:payiconView];

        UIImage *btcicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/bitcoin.png", kSelfBundlePath]];
        UIImageView *btciconView = [[UIImageView alloc] initWithImage:btcicon];
        btciconView.frame = (CGRect){{0, 21}, btciconView.frame.size};
    //  btciconView.center = (CGPoint){headerView.center.x, btciconView.center.y};
        btciconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
        [headerView addSubview:btciconView];

1 个答案:

答案 0 :(得分:1)

您正在添加所有子视图处于相同位置。所有UIView帧都从相同的'x'位置'0'开始。你需要改变第2帧和第3帧x位置。 ( Change your CGRect 'X' position)代表第二和第三UIView

bugiconView.frame = (CGRect){{0, 21}, bugiconView.frame.size};
payiconView.frame = (CGRect){{0, 21}, payiconView.frame.size};
btciconView.frame = (CGRect){{0, 21}, btciconView.frame.size};

希望它有所帮助...