IOS Miscellaneous Pen-11 (implements a size that cannot be changed externally uiview)

Source: Internet
Author: User

I think the topic may not be very clear, then I would like to introduce in detail this essay content.

The size of the UIView control cannot be changed externally.

This is said to be uiview, but in fact, most controls are not just uiview.

What to do if you want to implement a size that cannot be changed externally.

The first is to rewrite the setframe so that it prescribes itself as size, as follows

  testview.m//  cx-Implementation cannot be changed externally UIView size////  Created by Ma C on 16/3/25.//  Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "TestView.h" @implementation testview-(void) Setframe: (cgrect) frame{frame.size        = Cgsizemake (+);        [Super Setframe:frame];} @end

After rewriting the setframe we can test it.

I'm in VC. The size of the TestView is set to {200,200}.

This shows that the size of the Uitestview cannot be changed externally

But the following results are not.

We first set up the Uitestview center.

Then set the Uitestview bounds

  viewcontroller.m//  cx-Implementation cannot be changed externally UIView size////  Created by Ma C on 16/3/25.//  Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "ViewController.h" #import "TestView.h" @interface Viewcontroller () @end @implementation viewcontroller-(void) viewdidload {    [super viewdidload];            TestView * view = [[TestView alloc]init];        View.center = Self.view.center;        View.bounds = CGRectMake (0, 0, $, +);        [Self.view Addsubview:view];        NSLog (@ "%@", Nsstringfromcgrect (View.frame));    } @end

The results are as follows

Visible: Uitestview size has changed, it's okay.

Let's rewrite the bounds.

  testview.m//  cx-Implementation cannot be changed externally UIView size////  Created by Ma C on 16/3/25.//  Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "TestView.h" @implementation testview-(void) Setframe: (cgrect) frame{frame.size        = Cgsizemake (+);        [Super Setframe:frame];} -(void) SetBounds: (cgrect) bounds{        bounds.size = cgsizemake (+);        [Super Setbounds:bounds];} @end

The results are as follows:

  testview.m//  cx-Implementation cannot be changed externally UIView size////  Created by Ma C on 16/3/25.//  Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "TestView.h" @implementation testview-(void) Setframe: (cgrect) frame{frame.size        = Cgsizemake (+);        [Super Setframe:frame];} -(void) SetBounds: (cgrect) bounds{        bounds.size = cgsizemake (+);        [Super Setbounds:bounds];} @end

This concludes that if you want the UIView control to be unable to change size externally, we only need to rewrite the frame,bounds.

In the same vein, we can also implement some other operations.

IOS Miscellaneous Pen-11 (implements a size that cannot be changed externally UIView)

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.