Add style for every buttons in ViewController - ios

i have over 20 buttons in my XCode project, and i want to add border to every of them. is it possible to like select all the UIButtons in the storyboard and then perform codes on them?
// For example
buttons.borderColor = [[UIColor darkGrayColor] CGColor];
buttons.cornerRadius = 8;
buttons.borderWidth = 1;

You could use the UIAppearance protocol.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAppearance_Protocol/index.html

Related

How to add a shadow effect for UINavigation bar?

Do you have to add it programmatically? Or there is an option from the main.storyboard interface builder?and if there is a way from storyboard , How do you add it ?
Something like this :
Thanks
You would have to add it programatically.
Do this in your UINavigationController Class
self.navigationBar.shadowColor = UIColor.blackColor().CGColor
self.navigationBar.shadowOffset = CGSizeMake(5, 5)
self.navigationBar.shadowRadius = 5
If you'd like to do it from Storyboard you have to create an image and set the Shadow Image.
It is however easier to do it programatically on the either a UINavigationController subclass, or within the first view in the UINavigationController stack if you just want a very simple shadow effect.
self.navigationController.navigationBar.layer.shadowColor = [[UIColor blackColor] CGColor];
self.navigationController.navigationBar.layer.shadowOffset = CGSizeMake(2.0f, 2.0f);
self.navigationController.navigationBar.layer.shadowRadius = 4.0f;
self.navigationController.navigationBar.layer.shadowOpacity = 1.0f;

Adding shadow to floating UICollectionView headers

I have an UICollectionView with 2 sections, each one has its own floating header.
My question is if is there any way to add shadow below the header that will be displayed on the collection's cells?
Make a pointer to your collection view's header. (Info)
Then apply following CALayer? effect:
Objective-c
yourObject.clipsToBounds = NO;//necessary, dont change
yourObject.layer.masksToBounds = NO;//necessary, dont change
yourObject.layer.shadowColor = [[UIColor blackColor] CGColor];//color
yourObject.layer.shadowOpacity = 0.5f;//translucency (alpha)
yourObject.layer.shadowRadius = 1.5f;//size | spread
yourObject.layer.shadowOffset = CGSizeMake(0.0f, 2.5f);//direction (x,y)
Convert to Swift as needed.

Style controls on iOS 6 with layers are wrong? (From iOS7)

I'm creating an app and I'm styling some controls like text fields and buttons with layers (for example changing the border color and thickness), or simply by changing the background color of the control from the Interface Builder.
On iOS 7 it's all working good, but when I run the application on iOS 6 (simulator) I see old style controls plus borders of the layer.
The two versions were running both with the iOS 6.1 SDK.
Here is the screen of what is happening: (I can't post images for the reputation on SO)
EDIT:
The code for the textfields i use is this:
UITextField* textField = (UITextField*) aView;
textField.layer.cornerRadius = 0.0;
textField.layer.borderColor = [[UIColor lightGrayColor] CGColor];
textField.layer.backgroundColor = [[UIColor whiteColor] CGColor];
And for the "Login" button i simply changed the background color in the IB.
In order to remove the border of the textFields, set the borderStyle to none:
textField.borderStyle = UITextBorderStyleNone;
As for the Login button, don't forget to set the button's type to Custom in IB.
Tell me if that works.

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.

simplest (rectangular) drop shadow for an UIView

I've seen lots of snippets that either: are too complicated for something as simple as a drop shadow, requiring subclassing UIView and using quartz2d calls, or I can't get them to work.
I just want to do this on a view I'm adding as a subview to another one (the subview is taken from another viewController I'm just allocating - I know that's probably not nice but oh well), no IB or anything. what's the simplest / most accepted way to go about it? would it be different if I want it to work on iOS 4?
It's as easy as importing <QuartzCore/QuartzCore.h> and using a similar snippet as below:
self.viewAboutContainer.layer.shadowColor = [[UIColor blackColor] CGColor];
self.viewAboutContainer.layer.shadowOpacity = 0.7;
self.viewAboutContainer.layer.shadowRadius = 4.0;
self.viewAboutContainer.layer.shadowOffset = CGSizeMake(5.0f, 5.0f);
self.viewAboutContainer.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.viewAboutContainer.bounds].CGPath;

Resources