Reputation: 117
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];
Upvotes: 0
Views: 149
Reputation: 196
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...
Upvotes: 1