Drop shadows on iPhone Clock App "Alarm" tab - iphone

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.

Related

Autolayout - UITableViewCell with ImageView - Margin?

I have a problem when i will try to make a left/top/bottom margin with an UIImageView in a cell. It don't care what i will try to set as Top/Bottom/Left Space, i will always get the same result -> all Images are without any margin.
I have a fixed height and width, i will just want to add top/left margin.
Is there any way to force the Autolayout to add a margin here?
Thanks in advance for any tips.
Edit:
Thanks for you answer. Ill tried it, but its still not working. There is always no margin between cell and image:
Here are my constraints. (ill just take 8px as space to superView)
Actually i could't get quite to work on this issue. but i am sure that it will going to work if you try this things in your code.
Using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights
Edit:
Set the new UIImageView size and position to the values shown in the screenshot below.
Now select UIImageView and add following contraints.
Set leading, top and bottom to 20.
Set width and height to 100.
Make sure that Constrain to margins is not checked.
Tap the Add 5 constraints button.
Select the image view to show its constraints, and then select its bottom constraint to edit it. In the attributes editor, change its Relation to Greater Than or Equal and its Priority to 999.
Next, select the image view to show its constraints and then select its height constraint. In the attributes editor, change its Priority to 999.
Likewise, select the image view’s width constraint and change its Priority to 999.
To set following constraints, you will get you answer.
Add this code in cellForRowAtIndexPath
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectZero];/// change size as you need.
CGRect frame = separatorLineView.frame;
frame.size.height = 5.0;
frame.size.width = tableView.frame.size.width;
separatorLineView.frame = frame;
separatorLineView.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:separatorLineView];
return cell;
OR
Follow these links Autolayout or Autolayout programatically
Now use these constraints
storyboard
simulator
This might helps you :)

Transparent row of pixels between section header and first cell in a grouped UITableView

As the title says, I have a problem with a row of transparent pixels that I can't get rid off.
I attached an image as it's worth 1000 words.
The problem is not present for the section footer (where I'm also using a custom view).
I have checked and double checked that I return the correct size for the height of the section.
Any ideas?
EDIT:
I've added a test project so you can play around. The purple color represents the background color. The white rectangles are the header/footer and the light gray are some dummy cells. The issue is clearly visible in the project.
TransparentRowBug XCode project
You will also see that I use a lot of clear colors. Unfortunately changing the colors in order to hide the problem is not a viable solution for me.
Feel free to give it a try (or more)!
Thanks a lot!
EDIT2:
After further investigation, I concluded that the line of pixels come from the tableview separator. In the test project I am setting the separatorColor to clearColor. If I change this to another color, I will get exactly that row of pixels in the new color. Even though I set the separator style to none, it seems to have no effect on grouped tables.
I finally figured this one out, after almost 2 days of testing (and hair loss).
As I said in my comment above, simply returning a smaller height in the heightForHeader method doesn't work. To make it work you need to take your desired header view, insert it in a dummy/container view with the exact same size and then give this container to the tableView as the header.
Then, when you return a smaller size for the header, it magically (and it really is magic for me) manages to overlap that annoying row of pixels.
By the way, I concluded that the row of pixels is due to the cell separator line.
If someone is interested, I can upload the working test project again.
I'm not sure to understand if that's what you're asking, but I figured two days ago that you can reduce default space between sections in a tableView...
By making heightForHeader returning a negative value! Dirty, but... works.
I hope that help...
I encountered this problem too. I had a UITableView with grouped sections. Between the first section header and first cell, there was a 1-point (2 Retina pixels) gap where the background bled through.
If the background cell color is uniform, then you can assign the backgroundColor of the UITableView to hide this gap.
In my case, the backgroundColor/backgroundView was used for a non-scrolling patterned background on other cells. The solution proposed by mluisbrown works perfectly. I would like to re-emphasize this solution:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView* topTabView = /* initialized elsewhere */;
CGRect sectionHeaderSize = CGRectMake(0, 0, 320, 46);
UIView* wrapperView = [[UIView alloc] initWithFrame:sectionHeaderSize];
topTabView.frame = sectionHeaderSize;
[wrapperView addSubview:topTabView];
return wrapperView;
}
Add a separator between header view and first row :- In view for Header in section delegate method add a subview self.separator //#property (nonatomic, strong) UIImageView *separator;
- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section {
return 41;
}
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section {
self.headerView = [[UIView alloc] init];
self.headerView.backgroundColor = [UIUtils colorForRGBColor:TIMESHEET_HEADERVIEW_COLOR];
self.separator = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"seperator.png"]];
self.separator.frame = CGRectMake(0,40,self.view.frame.size.width,1);
[self.headerView addSubview:self.separator];
return self.headerView;
}
Grouped UITableView will take header, cell and footer as a single entity. So the white transparent view is the footer view which can be dealt by decreasing the footer height as shown in the screenshot. I hope it works
Good Luck :)

Custom UITextField

How would I go about creating a UITextField like the one in this image?
It appears to be slightly larger, specifically in height.
This can be done much better and simpler with a stretchable image:
UIImage *fieldBGImage = [[UIImage imageNamed:#"input.png"] stretchableImageWithLeftCapWidth:20 topCapHeight:20];
[myUITextField setBackground:fieldBGImage];
Think of the background of the text field as split into three sections. A middle section which can be stretched and caps on the ends. Create an image which only needs to be long enough to contain one pixel of this repeating section (a very short text field), and then create a stretchable image from it using stretchableImageWithLeftCapWidth: topCapHeight. Pass the width of the left end cap into 'leftCapWidth.' You can make it stretch vertically as well, but if your background image is the same height as your text box it wont have an effect.
If you're familiar with 9-slice scaling in Flash or Illustrator it's exactly the same concept, except the middle sections are only one pixel wide/tall.
The advantage of this is you don't have to worry about multiple layered objects scaling together and you can resize your text fields any time and the background will stay in tact. It works on other elements too!
You probably want to use the background and borderStyle properties of UITextField. Setting borderStyle as UITextBorderStyleNone and create a custom background image to be stretched and used as the background property would be one approach.
I suggest taking a look at those properties in the UITextField class reference.
You can do this by:
yourTextField.borderStyle = UITextBorderStyleNone;
yourTextField.background = [UIImage imageNamed:#"email-input.png"];
And if you want to give margin to your text inside the textfield, you can do this by:
// Setting Text Field Margins to display the user entered text Properly
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
yourTextField.leftView = paddingView;
yourTextField.leftViewMode = UITextFieldViewModeAlways;
You can also do this through Interface Builder.
just use the following line and it should work
textfield_name.background = [UIImage imageNamed : #"yourImage.png"];
here, "yourImage" is the background image you wanna set...
however, this will work only if your button isnt a roundrect button.So, you can change the type of the button in the Interface Builder or you can use
textfield_name.borderstyle = UITextBorderStyleNone or UITextBorderStyleBezel
and you r gud2go....!
Take an uiimageview set its image property to the image you want as uitextfield background. And on top of this uiimageview place an uitextfield with borderstyle none. This you can do directly in interface builder.

Programmatically determining padding for grouped UITableView

Is there a way to programmatically get a UITableView's 'grouped' style padding?
I'd like to size some things in my screen but I need to know how far left or right to place them on a grouped UITableView's UITableViewCell.
Since you are using the grouped style for your table view, you should be able to use the rectForSection: method to get the CGRect where that section will be drawn. You may have to already have added your cells to your view, however.
CGRect sectionRect = [tableView rectForSection:0];
int paddingLeft = sectionRect.origin.x;
As I see it, 'grouped' style padding == the origin of cell.contentView. but the value is assigned by table view only in tableView:willDisplayCell:forRowAtIndexPath: and is equal to 10 on iPhone/iPod Touch. querying it in cellForRowAtIndexPath: results in 0.

How to change the width of the row of a UITableView

Can we resize the width of the row of a UITableView.
What exactly are you trying to accomplish?
I'm not 100%, but I am pretty sure each row is going to be with same width as the parent table. However, if you have a custom UITableViewCell, you can make it transparent, and organize your objects on the cell's view to mimic a different sized cell. For example if you wanted a cell to be 50px less wide than the other cells and indented, you could place a white UIView on the transparent cell, make it 50px less wide than it should be, and position it to the right.
Make sense?
I understand this is an old question, but I need a table cell to be less than the width of the screen, but still be scrollable by touch on either edge, and the cell highlight not to be full width.
I overrode the UITableViewCell setFrame method, like so:
- (void) setFrame:(CGRect)frame {
if (frame.size.width > 540.0f) {
frame.origin.x = (frame.size.width-540.0f)/2.0f;
frame.size.width = 540;
}
[super setFrame:frame];
}
I guess this is a slightly hacky solution, but it works a treat!
Hope this helps someone.
Only if you fit the whole table into a smaller area.