Custom cell with three buttons (with icon) in objective c

旧巷老猫 提交于 2019-12-12 01:52:33

问题


I was using PSButtonCell's for links but three individual ones took up too much space so I'm trying to create a custom cell with three buttons in one row; basically like 3 floating icons.

I've got some code for creating a tableview with icons, but currently I do not know how to space them properly (all the icons currently overlap), and I have no idea how I should go about adding tap listeners to the views. Does this look like something I could modify to do what I want? If not does anyone have a better solution they could provide for me? thanks a lot heres my code for the icons

- (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:


You're adding all the subview is in same position. All UIView frame start from same 'x' position '0'. You need to change 2nd and 3rd frame x positon . ( Change your CGRect 'X' position) for second and third 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};

Hope it helps...



来源:https://stackoverflow.com/questions/42730753/custom-cell-with-three-buttons-with-icon-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!