Tableview: Add a shadow - uitableview

My designer asked me to add a shadow to the cell of my tableview like this:
Currently I have implemented everything functional, even the Top | Latest header-view. How can I add such a shadow to the end of each tableviewsection?

Below is my solution. In this situation don't forget to set your view's backgroundColor even it's whiteColor and shadowOpacity.
And give an extra space around your cellSubView to show the shadow.
You can set appropriate values instead of mines depending on your requirements.
Hope this helps.
cellSubView.backgroundColor = [UIColor whiteColor];
cellSubView.layer.shadowColor = [UIColor blackColor].CGColor;
cellSubView.layer.shadowOpacity = 0.5;
cellSubView.layer.shadowOffset = CGSizeMake(0,10);
cellSubView.layer.shadowRadius = 3;

Related

UITableViewCell reorder control clips view in iOS 13

I put a background image in a UITableViewCell to make it more visually appealing. In iOS 13, the background image is clipped by the reorder control.
This did not happen with older versions of the OS.
The code is simple:
// Put a border around mBackgroundImage. Make it slightly smaller than the size of the cell so that the border doesn't run all the way to the edges.
cell.mBackgroundImage.frame = CGRectMake(2, 2, cell.frame.size.width-4, cell.frame.size.height-4);
cell.mBackgroundImage.layer.cornerRadius = 4;
cell.mBackgroundImage.layer.borderColor = [UIColor colorWithWhite:0.92 alpha:1.0].CGColor;
cell.mBackgroundImage.layer.borderWidth = 1;
cell.mBackgroundImage.layer.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.95 alpha:1.0].CGColor;
Any suggestions?
Problem solved by setting cell.contentView.clipsToBounds to NO. It looks like cell.contentView.clipsToBounds=YES had been ignored prior to iOS 13.

Custom Rounded Button without Corner Radius

how do we subclass a UIbutton and customize it so that it has a round end like this one on Periscope. The Following Button.
I would like to PREVENT using layer.CornerRadius though.
Using a BezierPath perhaps? but I have a math problem creating the Path.
Any thoughts? Thank you
I have created that button using the layer.CornerRadius as below :-
self.buyButton.layer.cornerRadius = self.buyButton.frame.size.height/2;
self.buyButton.clipsToBounds = YES;
[UPDATED CODE - FOR SHADOW]
self.buyButton.layer.masksToBounds = NO;
self.buyButton.layer.borderWidth = 1.0f; //Just for look n feel
self.buyButton.layer.shadowColor = [UIColor greenColor].CGColor;
self.buyButton.layer.shadowOpacity = 0.8;
self.buyButton.layer.shadowRadius = 12;
self.buyButton.layer.shadowOffset = CGSizeMake(12.0f, 12.0f);
But why u don't want to use the method already provided as per your custom requirement I don't think you need to use bezier path for this.
UPDATED SCREENSHOT :

How to set the background color of Customview(NSView)in mac applications?

I have tried to change the background color of NSView like this in iOS,
self.titleview.backgroundcolor = [UIColor redColor];
But no property like that exists so after it, I tried,
self.titleBarView.layer.backgroundColor = [[NSColor redColor]set];
But it shows some error.
self.titleBarView.layer.backgroundColor = [NSColor redColor].CGColor;
If you do not want to use view.layer. You can use NSBox (with custom style) over NSView. NSBox has fillColor property.

UITextField Set Border

I want to make my login interface a little bit more fancy. So I wanted to build somethin like this:
Thats what i Have to far:
self.usernameTextField.layer.borderWidth = 1.0f;
self.usernameTextField.layer.borderColor = [[UIColor colorWithRed:171.0/255.0 green:171.0/255.0 blue:171.0/255.0 alpha:1.0] CGColor];
self.usernameTextField.layer.cornerRadius = 5;
self.usernameTextField.clipsToBounds = YES;
self.passwordTextField.layer.borderWidth = 2.0f;
self.passwordTextField.layer.borderColor = [[UIColor colorWithRed:171.0/255.0 green:171.0/255.0 blue:171.0/255.0 alpha:1.0] CGColor];
self.passwordTextField.layer.cornerRadius = 5;
self.passwordTextField.clipsToBounds = YES;
How can I connect them? There is still a gap between the two UITextFields..
Put plain image background like your interface and put two text fields on that image and set boarder style like below.
[yourTextField setBorderStyle:UITextBorderStyleNone];
The example you show is almost certainly using a table view. If you want to mimic it created a grouped table view with 2 static rows and add your text fields to each row. Make sure the text fields border style is set to none (it should be the default in IB), then set your placeholder text and color. If you want the icons, that is probably just a small UIImageView to the left of the text field.
You can set your UITextField border style to none.
[self.textField setBorderStyle:UITextBorderStyleNone];
and then use custom background images, to get the desired look.
Create your both TextField custom type. Dont set any border style.. Fix the image in ImageView and then place the two text field frame for the text in imageview.

How do I make a UISwitch under iOS 7 not take the background colour of the view behind it?

It looks like this whenever off:
While I'd prefer more of a grey background. Do I really have to use a UIImageView?
Here is how I changed the fill color of my iOS7 UISwitch.
First you need to import QuartzCore.
#import <QuartzCore/QuartzCore.h>
Then set the background color and round the UISwitch's corners.
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0.0, 0.0, 51.0, 31.0)];
mySwitch.backgroundColor = [UIColor redColor];
mySwitch.layer.cornerRadius = 16.0; // you must import QuartzCore to do this.
[self addSubview:mySwitch];
This will give you a UISwitch with a custom off (background) color.
Hope this helps someone:)
You can set the setOnTintColor property of your UISwitch to the color you desire.
You can also set this for the switch in Interface Builder. Just set the background colour of the UISwitch to whatever colour you want (white, in the example below), then set a User Defined Runtime Attribute of layer.cornerRadius = 16:
There's no API support for changing the off fill color of a UISwitch.
Adjusting the tintColor will only affect the outline, and adjusting the backgroundColor will affect the whole frame, including the parts outside the rounded bounds.
You either have to place a properly shaped opaque UIView behind it or - easier - use a custom open source implementation, such as MBSwitch, which allows you to set the off fill color.
You can also use an image as background, using the [UIColor colorWithPatternImage];
mySwitch.onTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"toggle-bg-on"]];
mySwitch.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"toggle-bg-off"]];
Adding to Barry Wyckoff solution : set tint color also
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0.0, 0.0, 51.0, 31.0)];
mySwitch.backgroundColor = [UIColor redColor];
mySwitch.layer.cornerRadius = 16.0; // you must import QuartzCore to do this.
mySwitch.tintColor = [UIColor redColor];
[self addSubview:mySwitch];

Resources