IOS adds the color of the rounded corner, outer frame, and outer frame to the control in xib or storyboard.

Source: Internet
Author: User

IOS adds the color of the rounded corner, outer frame, and outer frame to the control in xib or storyboard.

If you want to add the rounded corner and the width of the outer frame to the control in xib and storyboard, you only need to do so.

Layer. borderWidth: Set the out-of-box width attribute.

Layer. cornerRadius

You only need to set the value for the attribute.

 

Of course, it cannot be seen after xib is modified. The result is as follows:

What should I do if I want to modify the color of the outer box in xib and storyboard ?? Only other methods can be implemented, such as classification.

Add category

Then

Generate this file

. H file

1 #import <QuartzCore/QuartzCore.h>2 3 @interface CALayer (LayerColor)4 5 - (void)setBorderColorFromUIColor:(UIColor *)color;6 7 @end

In the. m file

Add a set method

 1 #import "CALayer+LayerColor.h" 2  3 @implementation CALayer (LayerColor) 4  5 - (void)setBorderColorFromUIColor:(UIColor *)color 6 { 7     self.borderColor = color.CGColor; 8 } 9 10 @end

If your UIColor prompts that the error cannot be found, you have not imported the UIKit framework.

Import It In The. h or global header file.

# Import <UIKit/UIKit. h>

This completes the basic work.

Now you can add this attribute in the xib or storyboard just like adding a control outer box and a rounded corner.

Type is color

Note that this is the set method, so if the method added in the category is

-(Void) setBorderColorFromUIColor :( UIColor *) color;

The attribute should be layer. borderColorFromUIColor.

For example

-(Void) setColorFromUIColor :( UIColor *) color;

The attribute is layer. colorFromUIColor.

Run:

 

 

In this way, we can understand how this method is used. Otherwise, the color setting is invalid because the method is incorrect.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.