Styling Buttons in iOS Xcode

I am new to iOS development. In Windows Phone development, we use the control buttons in the Global place application to determine the style (for example,) of the control button, and simply use this style anywhere in any button in the application, assigning the style property.

Is there something similar in iOS Xcode? I know that I can customize the button in the properties and appearance window in Xcode. But in this way I have to style every similar button in the application. and if there is any change, I have to change it everywhere. What do iOS developers do in such situations?

+7
ios xcode swift xcode6
source share
3 answers

If you want to style all the buttons in your application in a standard way, then you will create an appearance proxy for UIButton . You get one of them by calling the UIButton.appearance() class method, and then style the return value the way you want your buttons to look. You can also make a finer-grained appearance by calling methods like UIButton.appearanceWhenContainedIn() .

+4
source share

Create a subclass of UIButton. For example, to create a UIButton with rounded corners and a border:

Header file

 #import <Foundation/Foundation.h> @interface XYRoundedCornerButton : UIButton @end 

Implementation file

 ...import headers etc... @implementation XYRoundedCornerButton - (void)awakeFromNib { [super awakeFromNib]; self.layer.cornerRadius = 8.0f; self.layer.masksToBounds = YES; self.layer.borderRadius = 1.0f; self.layer.borderColor = UIColor.redColor; } @end 
+3
source share

If you use a storyboard, you do not need to add code to the class. Just drag and drop one button and set all the necessary properties, be it background color, radius of the corner, etc., Whatever you want. And then either copy it and paste it wherever you want, or select the ALT + DRAG button.

+2
source share

All Articles