Stefan
Stefan

Reputation: 29017

Clipping within an UIView with some subviews

I have some buttons in an UIView. My problem is, that they get cut off at the right side of the UIView. How do I prevent this?

alt text http://img.skitch.com/20090629-mj32p1bkff476256pwrpt69n2d.png

I've checked already Interface Builders clip property, but it's no solution for this problem.

Regards

Upvotes: 0

Views: 1966

Answers (3)

obsoleteModel81
obsoleteModel81

Reputation: 433

I have been using java and only recently began learning Apple's Obj-C framework.

An alternative to scrolling and row-breaking is using a "grid" layout with 1 row and n columns, where n is the number of buttons. Each cell has a fixed size. And you will have to resize your buttons (the subviews) in your superview's setNeedsLayout: method to whatever width you need such that all buttons fit the row.

See java's GridLayout class.

Upvotes: 1

Stefan
Stefan

Reputation: 29017

Kendall, thanks for your answer.

Here is my solution:

    if(previousFrame.origin.x + theStringSize.width > 220){
            roundedButton.frame = CGRectMake(15, previousFrame.origin.y + 30 ,  theStringSize.width + 8, theStringSize.height);
            [myContainer insertSubview:roundedButton belowSubview:[tagsContainer.subviews lastObject]];
        }else {
            roundedButton.frame = CGRectMake(previousFrame.origin.x + previousFrame.size.width + 5, previousFrame.origin.y,  theStringSize.width + 5, theStringSize.height);
            [myContainer insertSubview:roundedButton belowSubview:[tagsContainer.subviews lastObject]]; 
        }

I calculate, how many pixel I've moved from the left side. At some threshold (in my case 220) I start a new line.

Upvotes: 0

It seems like either you made these buttons programmatically, or you reiszed the initial IB view window to be larger and expected it to shrink down to the fit the screen.

The buttons in question cannot fit on the screen as they are - what effect are you looking for?

If you want the buttons all to fit you could set the text size to be smaller, and then they could fit.

If you want the buttons the size they are then you'll have to make another row, or put the buttons into a side scrolling container.

Upvotes: 1

Related Questions