How to draw multiple lines(Grid) in UITableView Cell? - iphone

I want to add multiple columns in UITableView. I have created one CustomeTableCell with two lines used - (void)drawRect:(CGRect)rect method. But, i able to draw only 2 lines (3 columns). I have to draw multiple lines (Vertically),Eg: 5 - 10 columns. How can draw multiple lines in tableviewcell. Can you please suggest me any idea/sample code to complete this? Thanks in advance.

What about making the backgroundColor black. Adding x white subviews to the contentView of the cell, with a 1px margin between them?
This would create the desired column look, and also add the benefit of being able to acces the columns easily, if the views were set as properties.

I had the same issue. I took a UIView and set one image of 4X2 as its background and set the frame of uiview as CGRectMake(0, 40, 330, 2). and then added the UIview in cell
[cell addSubview:uiviewwithImage];
Hope this method helps you. Thanks.

Instead of actually drawing on the tableView try layer.border properties on the subviews of the cell.
This solves the issue if the subview edge & the grid line you want to draw have same X or Y coordinate.
If you want a margin between the subview & the grid line this may not work.

Related

Aligning rows in UITableView

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 can I hide the row separators in a UITableView without hiding the group borders?

I have a grouped UITableView, and I want to hide the lines between the rows. When I set the separatorColor to clearColor, the lines disappear; but so does the border around the groups. Is there a way for me to hide the lines between the rows, but keep the border around the groups?
Writing this out of my head, and not sure if it would work. Give it a try
self.tableView.layer.borderColor = [UIColor grayColor].CGColor;
self.tableView.layer.borderWidth = 1.0f;
You need to import and add the necessary framework to the Build Phases section of your target.
Maybe is a bit later but I have a little "fix". In your cell view you have to add a UIView with the same color than your cell background and put it at the botton of your cell. This new view will put over the separator line. So you have to show it in every cell less the last one, using setHidden method. And here you have, no separator!

Represent Number Line in iphone app

I am looking to display number line in my application
How this can be done? I also want to control number like programatically
you can use views with different sizes and background colours. Use #define -s for the fixed sizes.
You should have 3 functions:
one that draws the horizontal red/blue rects
-(UIView *) drawHorizontal:(CGRect)frame withColor:(UIColor)theColor;
one that draws vertical spacers and labels underneath. Iterate for whole line width.
-(UIView *) drawVertical:(CGPoint)centerPosition withLabel:(int)number;
Your number line should be stored as an NSArray of NSDictionaries containing the position (index) and length of the horizontal red/blue lines.
Hope this helps.
There's no easy standard component to do this. You will need to subclass UIView and override drawRect. Then you can use Core Graphics to draw the number line.

Height of UIPicker

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

Drop shadows on iPhone Clock App "Alarm" tab

In the clock app that comes with the iPhone there is a tab view for setting alarms. In that view each of the UITableViewCell instances have a drop shadow around them. Does anyone know how to achieve the same effect?
Also it looks like the tab bar at the very bottom has a drop shadow above it as well.
Ideas on how to achieve the same look would be greatly appreciated.
I was wondering how to do that and it just occurred to me to use the UITableView's footer view:
myTableView.tableFooterView = myCustomViewWithDropShadowImage;
I would guess that there is an extra cell which contains just a background image which is the transparent dropshadow. If it's not a cell (because that might create scrolling weirdness) it is probably an extra view positioned below the bottom cell of the UITableview which - again - simply contains an image of the drop shadow.
Like Thomas said, create a 100% width image (say, 320 x 40px on non-retina devices) and create 4 instances of UIImageView with it. The first, at the top of your main view. The second, at the bottom, and in addition do this:
UIImageView* bottomShadow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"BottmShadow.png"]]
bottomShadow.transform = CGAffineTransformMakeScale(1, -1);
(Flip it vertically)
Then, do the same with the other two, but place them as subviews of the Table View. One of them just outside the first row:
CGRect tableTopShadowFrame = tableTopShadow.frame;
tableTopShadowFrame.origin.y = -(tableTopShadowFrame.size.height);
[tableTopShadow setFrame:tableTopShadowFrame];
and the other just below the last row (you need to know the height of all the rows together. If your rows are all the same height, it is row height times number of rows).
Finally, you need to set the table's backgroundColor property to transparent
tableView.backgroundColor = [UIColor clearColor];
and possibly set some darkish gray for your main view's background color.