iOS use Xib to set fillet, border effects for controls

Source: Internet
Author: User
Tags border color uikit

To set rounded corners for various controls in Xib
    • Set up in code mode
@interfaceviewcontroller ()  @property (weak, nonatomic) iboutlet uiview *myview; @end  @implementation  viewcontroller-(void) viewdidload {[super viewDidLoad]; Span class= "Hljs-keyword" >self.myview.layer.maskstobounds = yes; self.myview.layer.cornerradius = 10;}         
    • Quickly set rounded corners with xib
      • Set up with the user Defined Runtime Attributes

Identity Checker
    • Detailed steps introduced
      • Click the UI Control
      • Click on the Identity Checker (the third button from the left) on the right side of Xcode
      • Locate the Runtime Attributes property, set by Key Path and Value
    • To set the fillet to the key Path:
      • Layer.cornerradius, note that the type of the key corresponding to Value should be set to String
      • Layer.maskstobounds, note that the type of the key corresponding to Value should be set to Boolean, yes when a checkmark appears on the right
      • Note: after testing, set UILabel 必须 the setting maskstobounds This key value pair, only then will appear the fillet effect; UIButton, UIView, Uiimageview just set Layer.cornerradius This key-value pair enables rounded corners
Xib to set the border effect for a control
    • Set up in code mode
-(void) viewDidLoad {[super viewdidload]; self.myview.layer.bordercolor = [uicolor redcolor]self.myview.layer.borderwidth = 2;}         
    • Quickly set borders with Xib
      • The method used is basically the same as the one described above Xib, the only difference is the setting of key Path key value pair
    • To set the border to the key Path:
      • Layer.borderwidth, note that the type of the key corresponding to Value should be set to String
      • Layer.bordercolor, note that the type of the key corresponding to Value should be set to Color

        When we run the program with joy, you will find that the result is not as you think, the border effect does not appear, then is our method wrong?

    • I don't know if you've noticed. Layer.bordercolor corresponds to a worthy type: color; You must remember that we set the color type as a CGColor good question on this.
      • According to the above method we set the border color as a UIColor type, of course, it will not work ah.
    • Here is a simple solution, we just need to create a classification for Calayer, the specific code is as follows:
Calayer+zzyxibbordercolor. h#import<QuartzCore/QuartzCore.h> @interface calayer ( Zzyxibbordercolor)  @end calayer+zzyxibbordercolor.m #import  calayer+ ZZYXibBorderColor.h " #import <uikit/uikit.h> @implementation calayer ( zzyxibbordercolor)-(void) Setbordercolorwithuicolor: (uicolor *) color{self.bordercolor = Color @end             

Note that when you set the border color, you need layer.borderColorWithUIColor to replacelayer.borderColor
Note: When we use Xib to set the fillet, border of the control, the key Path写错 system 不会报错 , but the operation will not achieve the desired effect



Wen/Nian (author of Jane's book)
Original link: http://www.jianshu.com/p/3f6a4343139e
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

iOS use Xib to set fillet, border effects for controls

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.