目标 c 中带有三个按钮(带图标)的自定义单元格 [英] Custom cell with three buttons (with icon) in objective c
问题描述
我将 PSButtonCell 用于链接,但三个单独的链接占用了太多空间,因此我尝试创建一个包含三个按钮的自定义单元格;基本上就像 3 个浮动图标.
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.
我有一些用于创建带有图标的 tableview 的代码,但目前我不知道如何正确间隔它们(当前所有图标都重叠),而且我不知道应该如何将点击侦听器添加到意见.这看起来像我可以修改的东西来做我想做的事吗?如果没有,有人可以为我提供更好的解决方案吗?非常感谢这是我的图标代码
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];
推荐答案
您添加的所有子视图都在同一位置.所有 UIView
框架都从相同的 'x'
位置 '0'
开始.您需要更改第 2 帧和第 3 帧 x 位置.(改变你的 CGRect 'X' 位置)
用于第二个和第三个 UIView
.
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};
希望能帮到你...
这篇关于目标 c 中带有三个按钮(带图标)的自定义单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!