1

I've got a little problem as seen below:

enter image description here

The cell has a background color, and the button doesn't. Still, it doesn't give me rounded edges, but corners. How can I fix that?

UIButton *meerKnop = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[[meerKnop layer] setCornerRadius:8.0f];
meerKnop.backgroundColor = [UIColor whiteColor];
meerKnop.frame = CGRectMake(11.0, (60.0 + (teller * 52.5)), 299.0, 50.0);
...        
[meerKnop addSubview:locationLabel];
...
[meerKnop addSubview:categoryLabel];

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
swipe.direction = UISwipeGestureRecognizerDirectionRight;
[meerKnop addGestureRecognizer:swipe];
[swipe release];

[meerKnop addTarget:self action:@selector(alertPressed:) forControlEvents:UIControlEventTouchUpInside];
meerKnop.tag = incId;
[cell addSubview:meerKnop];
Joetjah
  • 6,292
  • 8
  • 55
  • 90

3 Answers3

3

Try setting the corner radius of the layer of the button.

[button.layer setCornerRadius:10];

Remember to import if you are using layer property

Also, use:

[[button layer] setMasksToBounds:YES];

With this code the layer gets a corner radius of 10.0 and the -setMasksToBounds: tells the button’s layer to mask any layer content that comes below it in the layer tree. This is necessary in order for the layer to mask off the rounded corners.

Joetjah
  • 6,292
  • 8
  • 55
  • 90
Nithin
  • 6,435
  • 5
  • 43
  • 56
  • I'm afraid it didn't work for me. Is it possible the layer-option doesn't work because my button has its frame defined? – Joetjah Jun 09 '11 at 10:51
  • @Manjunath I've editted the answer (peer review) which makes it work for me. I missed the line `[button.layer setMaskToBounds:YES];`. With this, it works – Joetjah Jun 09 '11 at 11:07
1
UIButton *meerKnop = [UIButton buttonWithType:UIButtonTypeRoundedRect];

Change this to:

UIButton *meerKnop = [UIButton buttonWithType:UIButtonTypeCustom];

Edited:

UIButton *meerKnop = [UIButton buttonWithType:UIButtonTypeCustom];
[[meerKnop layer] setCornerRadius:8.0f];
meerKnop.backgroundColor = [UIColor redcolor];
meerKnop.frame = CGRectMake(11.0, (60.0 + (teller * 52.5)), 299.0, 50.0);

show me where the big white rectangle is appearing? (I hope u have cleared the cell background color).

Manjunath
  • 4,545
  • 2
  • 26
  • 31
  • This answer removed my borders and made the buttons a rectangle. So now, it's a big white rectangle with some text within. I think you've misunderstood the question – Joetjah Jun 09 '11 at 11:09
0

change the background colour of the button to same as that of cell.. it will take care of the rounded edges as there colour will become same as that of the background. sry i new.. i can think of this way only at the moment.. Hope it helps..

Hadi
  • 1,212
  • 2
  • 17
  • 31
  • It's an ok suggestion, but the cells look way uglier when everything is white, for example. And besides that, something like iOS should have an option like this, especially with Apple being so UI-oriented... – Joetjah Jun 09 '11 at 10:46