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
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.
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.
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.
Related
I've created a UITableViewCell with a textfield in it, which has a large diffused shadow underneath it. I've also set it up so that these big shadows can blend under its surrounding cells.
NB. Shadow has been HEAVILY emphasised here to show the problem.
The problem is that I want the shadow from my EMAIL textfield to blend underneath the password cell. i.e. I want both textfields to have a white background, but underneath them both I have the shadow. Something like this:
The reason this is a problem is because the UITableView is being rendered with upper cells "above" the lower ones. So any shadow from the cell at row 1 will bleed on top of the cells in rows 2, 3, 4 etc.
I was wondering if perhaps there is a way to change this rendering, and instead reverse the rendering so that a cell in row 4 is actually ABOVE rows 3, 2 and 1.
Or perhaps there is a way of setting the Password textfield so that no shadows are rendered on top of it?
Any help, very much appreciated!
Thanks to #Amr for pointing me in the direction of the cell.layer.zPosition.
The higher the value this is, the "closer" to the viewer the layer sits, so as long as each row has a higher value, it will appear "above" the shadows from any cells around it.
Since I use multiple sections in my code, I used this line to assign each cell above the previous one.
cell.layer.zPosition = CGFloat(indexPath.section) * 1000 + CGFloat(indexPath.row)
This may sound a newbie question, however I'm new to iOS dev.
I've got a UITableView on my iPad app. TableView has obly three rows, is there a way to tell UITableView to view rows vertically centered, i.e. to not from the top to down.
Figure out the sum of the heights of all 3 rows, call it MyTotalHeight.
float MyTotalHeight = heightOfRow0 + heightOfRow1 + heightOfRow2;
Set your
tableView.frame = CGRectMake(start_X, start_Y, tableWidth, MyTotalHeight);
If you want the contents of each row/cell to be centered vertically within the cell, this will depend greatly on what is in the cell. You will need to calculate the height of the content and then center that content vertically within the cell by adjusting it's frame.
You may want to try the UiTableView.sectionHeaderHeight property. Play with the number until the cells are centered vertically. If your using a plain table view, I don't know how well this will work for you.
--John
How to reduce/remove the left/right hand margin in a grouped UITableView?
Is there a way to do this without defining a custom view, i.e. using a UITableViewController directly?
I'm NOT asking here about the space between cells, it the space to the left & right of cells you see.
EDIT 1: Can I clarify:
already have a custom UITableViewCell ("#interface AppointCell : UITableViewCell") in my solution
I think the area to the left and right of these custom UITableViewCell's however are not directly from the cell itself - I say this only as when I put a border around the cell (via it's layer) I can see this - so therefore it seems like the space is from the UITableView itself (not the cells)
should point out again I'm using GROUPED mode for the table view
Sure; just adjust the frame of the UITableView so it's a little wider than its superview and a little to the left (in the negative X direction, in other words) of its left boundary.
I believe you have to create a custom cell view for your table which has padding on the left and right side.
You can also make the cell itself a bit wider. Add this method to your UITableViewCell subclass.
- (void)setFrame:(CGRect)frame {
frame.origin.x -= marginOffset;
frame.size.width += 2 * marginOffset;
[super setFrame:frame];
}
I Believe the offset should be 9 points. As a side note: If you set a custom background for the cell, you may also have to set it's selectedBackground.
You can use custom cell by extending UITableViewCell. I recommend you to take a look at http://www.e-string.com/content/custom-uitableviewcells-interface-builder
I've been trying to change the height of a pickerView. I would like it to show a single row instead of the default five rows.
help me plz
Better u can use PickerView Frame like this,
Pickerview.frame = CGRectMake(30,100,170,200);
You can't. UIPickerView can show either 5 rows or 3 rows, depending on the height of the frame you pass to the -setFrame: method. When I need a short UIPickerView, I'll pass a height of 100. The code in UIKit will adjust that height to be the closest allowed value.
I'll also note that this is for a very good reason. A one row pickerView, as has been noted elsewhere, would be fiendishly difficult to scroll. Also, the number of visible rows must be odd so that the currently selected row will be centered vertically. This means 3 or 5 rows, because 7 would make the thing way too tall to be practical on an iPhone.
As an aside, this also works with UIDatePicker for the same reasons. The exception is when the date picker is in the UIDatePickerModeCountDownTimer, which does not support the 3-row variant.
If you absolutely MUST have a one row picker view:
Create a UIView sized 170 wide by 55 tall.
Set the view properties clip subviews = YES
Add a UIPickerView as a subview of the UIView. Set its origin to 0, -80.5.
Then add a UIImageView sized 170, 55 as a subview to the UIView. Set its image to the one shown below.
(You can modify the image and make it stretchable to resize it horizontally)
Final Result:
did you try to implement numberOfRowsInComponent: ? If this doesn't change the size, did you try to set the picker's frame ?
ps: I agree with #Ritheesh#BoltClock, one row isn't a good idea
I have an UIView that can grow dynamically in width. The view also have subviews located inside it's bounds.
Default behavior seems to be that when the view's frame grows along the x axis, increasing frame.size.width, it always grows at the right edge, keeping the subviews fixed as if there were a fix left margin. However, when I want to expand the view on the left edge this doesn't work because of this behavior. In this case I want it to behave in a mirrored way, as if there were a fix right margin. I could of course "manually" move all subviews so it looks like that is the case, but that seems really awkward since there could be plenty of them.
So I guess the question really is if there is a way to shift a views bounds relative to it's subviews? Is maybe autoresizingMask the way to do this?
Thanks.
Maybe you should take a look at the AutoresizingMask property of a UIView subclass :-)
For example, if you have a UILabel called labelVideoTitle, you could set a mask like this :
[ labelVideoTitle setAutoresizingMask:UIViewAutoresizingFlexibleWidth ];
You can by the way add 2 mask at once like :
[ labelVideoTitle setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ];
Good Luck !
Edit : To increase the parent view frame size at the left edge, you could change too its X position to the left to give the impression wanted ^^ For example if you add 10 pt to the width, try modifying the X origin -10 pt :-)
In interface builder, you can graphically indicate in the CMD-3 (little ruler icon) Size Inspector what each element in your view should do when the parent view is resized: you can indicate which borders (top, left, right, bottom), the given element should "stick to" when the parent view is resized. You can also indicate whether the given element should itself resize (in either width or height) or stay the same size. Underneath the hood, this sets the autoresize mask for the UIView element you're editing, but especially for making an element stick to a particular border, Interface Builder is the way to go.
IB Size Inspector also has a neat little animation that shows you the effect on a hypothetical element (little red square) during a resize, given your settings to the left.