6. How to rewrite UIView?

Source: Internet
Author: User

//1. A program that creates UI controls often calls the method to perform initialization. Therefore, if you need to perform some extra initialization on the UI control, you can do so by overriding the method.

-(instancetype) initWithFrame: (cgrect) frame

{

self = [super initwithframe: frame];

if (self) {

}

return self ;

}

//2. The method is called automatically after the program has loaded the control through the nib file. Therefore, if the program needs to perform a custom initialization after the control is loaded in the nib file, it can be implemented by overriding the method meter.

-(instancetype) Initwithcoder: (nscoder *) coder

{

self = [super initwithcoder: coder];

if (self) {

}

return self ;

}

//3. If your program needs to draw the contents of the control itself, you can do so by overriding the method.

-(void) DrawRect: (cgrect) rect

{    

}

4. If your program needs more precise control over the layout of the child controls that the control contains, you can override the method implementation.

-(void) layoutsubviews

{

[Super layoutsubviews];

}

//5. The method is fired when the control adds a child control to completion.

-(void) Didaddsubview: (UIView *) subview

{

[Super didaddsubview: subview];

}

//6. The method is fired when the control is about to delete the child control.

-(void) Willremovesubview: (UIView *) subview

{

[Super willremovesubview: subview];

}

7. This method is fired when the control is added to the parent control when it is finished.

-(void) Didmovetosuperview

{

[Super Didmovetosuperview];

}

8. This method is fired when the control is added to the window to complete.

-(void) Didmovetowindow

{

[Super Didmovetowindow];

}

  

9. The method is fired when the user's finger starts to touch the control.

-(void) Touchesbegan: (nsset *) touches withevent: (uievent *) event

{

}

10. The method is fired when the user's finger moves on the control.

-(void) touchesmoved: (nsset *) touches withevent: (uievent *) event

{

}

11. the control is fired when the user's finger ends and moves on the control.

-(void) touchesended: (nsset *) touches withevent: (uievent *) event

{

}

12. the control fires when the user cancels the control.

-(void) touchescancelled: (nsset *) touches withevent: (uievent *) event

{

}

6. How to rewrite UIView?

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.